//Specific Functions for the Plan Finder Plans Page
var planTypes = new Array('pff', 'hmo', 'pre', 'msa');
function initPlans() {
    for(var x=0; x < planTypes.length; x++) {
        if(document.getElementById(planTypes[x])) {
            document.getElementById(planTypes[x]).onclick=expandCollapse;
            document.getElementById(planTypes[x]+"Link").onclick=expandCollapse;
        }
    }
//    document.getElementById("expandall").onclick=expandAll;
//    var inputs = document.getElementsByTagName('input');
//    for (var i=0;i<inputs.length;i++) {
//        if (inputs[i].type == "checkbox")
//            inputs[i].onclick = checkCompares;
//    }
}
function expandCollapse() {  
    finishAction(document.getElementById(this.id.replace(/Link/g,'')))
}
function expandAll() {
    if (this.firstChild.nodeValue == "Expand All") {
        this.firstChild.nodeValue = "Collapse All";
        for(var x=0; x<planTypes.length; x++) {
            el = document.getElementById(planTypes[x])
            el.className = "minus";
            el = document.getElementById(planTypes[x]);
            document.getElementById(el.id+'Body').style.display ="inline";
        }        
    }
    else {
        this.firstChild.nodeValue = "Expand All"    
        for(var x=0; x<planTypes.length; x++) {
            el = document.getElementById(planTypes[x])
            el.className = "plus";
            el = document.getElementById(planTypes[x]);
            document.getElementById(el.id+'Body').style.display ="none";
        }        
    }
}
function finishAction(el) {
    (el.className == "plus") ? el.className = "minus" : el.className = "plus";
    (document.getElementById(el.id+'Body').style.display == "none") ? document.getElementById(el.id+'Body').style.display='inline' : document.getElementById(el.id+'Body').style.display='none';
    
    var planTypes = new Array('pff', 'hmo', 'pre', 'msa');
    for(var a=0; a < planTypes.length; a++) {
        if((el.id).indexOf(planTypes[a]) == -1) {
    	document.getElementById(planTypes[a]).className = "plus";
    	document.getElementById(planTypes[a]+'Body').style.display = "none";
    	
	var collection = document.getElementById(planTypes[a]+'Body').getElementsByTagName('INPUT');
	    for (var b=0; b<collection.length; b++) {
	        if (collection[b].type.toUpperCase()=='CHECKBOX')
	            collection[b].checked = false;
	    }
   	
    	
        }
    }
    
    
}
var compareCounter=0;
var compareCounterMSA = 0;
var planType = "";

function checkCompares(id, plan) {

    if(planType.toString() != plan.toString()) compareCounter=0;
    
    if(id.checked==true)
        compareCounter++;
    else
        compareCounter--;
    
    if(compareCounter>3 || compareCounterMSA>0) {
        alert("You can only select a maximum of three plans to compare.")
        id.checked=false;
        compareCounter--;
    }
	planType = plan.toString();   
    
}
//Specific Functions for the Plan Finder Comparison Page
var theTable, theTableBody;
var remCount=0;
function initCompare() {
    var trs = document.getElementsByTagName('tr');
    for (var i=0;i<trs.length;i++) {
        trs[i].onmouseover = function () { if(this.className=="") this.style.backgroundColor = "#f0f0f0" };
        trs[i].onmouseout = function () { if(this.className=="") this.style.backgroundColor = "white" };
    }    
    theTable = document.getElementById("compareTable")
    theTableBody = theTable.tBodies[0]
}
function deleteColumn(col) {
    if(remCount<1) {
        var oneRow;
        if (theTable.tHead) {
            oneRow = theTable.tHead.rows[1]
            oneRow.deleteCell(1)
        }
        for (var i = 0; i < theTableBody.rows.length; i++) {
            oneRow = theTableBody.rows[i]
            oneRow.deleteCell(col)
        }
        remCount++
    }
}
