if (String.prototype.trim==null) String.prototype.trim = function()
{
    return this.replace(/^\s*|\s*$/g,'');
};

if (Array.prototype.unique==null) Array.prototype.unique = function( b ) 
{
	var a = [], i, l = this.length;
 	for( i=0; i<l; i++ ) 
 	{
  		if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 	}

	return a;
};

function activateActiveX()
{
	if (navigator.appName == "Microsoft Internet Explorer") 
	{	
		//Array of elements to be replaced
		var arrElements = new Array(3);
		arrElements[0] = "object";
		arrElements[1] = "embed";
		arrElements[2] = "applet";
		
		//Loop over element types
		for (n = 0; n < arrElements.length; n++) {
		
			//set object for brevity
			replaceObj = document.getElementsByTagName(arrElements[n]);
			
			//loop over element objects returned
			for (i = 0; i < replaceObj.length; i++ ) {
			
				//set parent object for brevity
				parentObj = replaceObj[i].parentNode;
				
				//grab the html inside of the element before removing it from the DOM
				newHTML = parentObj.innerHTML;
				
				//remove element from the DOM
				parentObj.removeChild(replaceObj[i]);
				
				//stick the element right back in, but as a new object
				parentObj.innerHTML = newHTML;
			
			}
		}
    }
}

function popupSubmit(obj,w,h) {
	window.open('','doPopup','width='+w+',height='+h,'toolbar=no,statusbar=no');
	obj.target='doPopup';
}

function helpMsg(msg)
{
	alert(msg);
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function ajax_createRequestObject() 
{
    var ro;
    var browser = navigator.appName;

    if(browser == "Microsoft Internet Explorer")
	{
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
	else
	{
        ro = new XMLHttpRequest();
    }
    
	return ro;
}

var LegacyAjax = ajax_createRequestObject();

function ajax_sendRequest(params) 
{
	var url = '/site/ajax.php?ajax=1';

	for(var key in params)
	{
		url += '&'+key+'='+params[key]
	}
		
	LegacyAjax.open('GET', url, true);
	LegacyAjax.onreadystatechange = ajax_handleResponse;
	LegacyAjax.send(null);
}

function ajax_handleResponse() 
{
	if(LegacyAjax.readyState == 4)
	{
		var response = LegacyAjax.responseText;
		var update = new Array();

		if(response.indexOf('|' != -1)) 
		{
			update = response.split('|');
			ids = update[0].split(',');
			for(var id in ids) 
			{
				document.getElementById(ids[id]).innerHTML = update[1];
			}
        }
    }
}

function toggleDisplay(toggler, targetId, expand, collapse)
{
	var target = $(targetId);
    if(expand == null)
    {
    	var expand = '+';
    }
    if(collapse == null)
    {
    	var collapse = '-';
    }
    
    if(target.style.display=='none')
    {
    	target.style.display='';
        toggler.innerHTML=collapse;
    }
    else
    {
        target.style.display='none';
        toggler.innerHTML=expand;    	
    }    
}

function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() {
            if (oldonload) 
            {
                oldonload();
            }
            func();
        }
    }
}

function setCookie( name, value, expires, path, domain, secure ) 
{
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}

function formUrl(formElement, newWin)
{
	if($F(formElement) != '')
    {
    	if(newWin)
        {
        	window.open($F(formElement));
        }
        else
        {
        	window.location.href = $F(formElement);
        }
    }
}

function toMoney(strValue, cents)
{
    strValue = strValue.toString().replace(/\$|\,/g,'');
    dblValue = parseFloat(strValue);

    blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
    dblValue = Math.floor(dblValue*100+0.50000000001);
    intCents = dblValue%100;
    
    if(isNaN(dblValue))
        dblValue = 0;
    
    if(isNaN(intCents))
        intCents = 0;

    strCents = intCents.toString();
    dblValue = Math.floor(dblValue/100).toString();
    if(intCents<10)
        strCents = "0" + strCents;
    for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
        dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
        dblValue.substring(dblValue.length-(4*i+3));

    if(cents)
    {
        return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
    }
    else
    {
        return (((blnSign)?'':'-') + '$' + dblValue);
    }
}