//*************************
//Collapse function
var COLLAPSABLE_PARENT_NAME = "collapsable"; 
var COLLAPSABLE_PARENT_TYPE = "div"; 
var COLLAPSABLE_CHILD_TYPE = "div"; 

var COLLAPSABLE_EXPAND = "[+]"; 
var COLLAPSABLE_SHRINK = "[-]"; 

init = function() { 
	//check for login status
	checkCookie('trilogiLogin');
	//assign collapse tags
    if(document.getElementById && document.createTextNode) { 
        var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE); 
        for(i=0;i<entries.length;i++) 
            if (entries[i].className==COLLAPSABLE_PARENT_NAME) 
                assignCollapse(entries[i]); 
    } 
} 

assignCollapse = function (div) { 
    var button = document.createElement('a'); 
    button.style.cursor='pointer'; 
    button.setAttribute('expand', COLLAPSABLE_EXPAND); 
    button.setAttribute('shrink', COLLAPSABLE_SHRINK); 
    button.setAttribute('state', -1); 
    button.innerHTML='+'; 
    div.insertBefore(button, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]); 

    button.onclick=function(){ 
        var state = -(1*this.getAttribute('state')); 
        this.setAttribute('state', state); 
        this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block'; 
        this.innerHTML = this.getAttribute(state==1?'expand':'shrink'); 
    };                    
    button.onclick(); 
} 

window.onload=init;

//*************************
//Open new window
function MM_openBrWindow(theURL) { //v2.0
	winName = 'Trilogi | Health Care Revenue Recovery';
	features = 'status=yes,menubar=yes,scrollbars=yes,width=690,height=550';
	window.open(theURL,winName,features); }
	
//*************************
//Determine if logged in
function checkCookie(name) {
	var value = readCookie(name);
	if (value=='true')
		document.getElementById('clientLogin').innerHTML='<span>CLIENT LOGIN</span><a href="clientLogin.php">Go To Client Page</a><br /><a href="clientLogin.php?logout">Logout</a>';
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name) {
	createCookie(name,"",-1);
	timedRefresh(true);
}

//*************************
//Refresh Page
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
//*************************
//Google Analytics Tracking
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function startAnalytics() {
	var pageTracker = _gat._getTracker("UA-5295252-5");
	pageTracker._initData();pageTracker._trackPageview();
}

if (window.addEventListener) {window.addEventListener('load', startAnalytics, false);}
else if (window.attachEvent) {window.attachEvent('onload', startAnalytics);}
