window.onload=function() {
    buildMenus();  //dynamically assign mouseover/out events to left menus
}

function validateSearchForm(objId) {
    if ($(objId).value == "") {
        alert('Please enter a search string!');
        return false;
    }
    return true;
}

function toggleBio(objId, linkNode) {
	var objNode = $(objId);
	if (objNode.style.display == "none"){
		objNode.style.display = "block";
		Element.update(linkNode, "Hide Biography");
	}	
	else {
		objNode.style.display = "none";
		Element.update(linkNode, "View Biography");
	}
	
}

function validateByRate(serializedForm) {
    alert(serializedForm);
    if (serializedForm.indexOf("=&") != -1) {
        return false;
    }
    return true;
}

function alert(message, header, messageBoxWidth, messageBoxHeight) {
    var alert_box = $('alert_message');
    alert_box.style.width = "300px";
    alert_box.style.height = "80px";
    var winDimensions = document.viewport.getDimensions();
    var scrollOffsets = document.viewport.getScrollOffsets();
    var mask = $('mask');
    if (messageBoxWidth != null && messageBoxWidth != '') {
        alert_box.style.width = messageBoxWidth + "px";
        alert_box.style.left = "50%";
        alert_box.style.marginLeft = "-" + (messageBoxWidth / 2) + "px";
    }
    if (messageBoxHeight != null && messageBoxHeight != '') {
        alert_box.style.height = messageBoxHeight + "px";
        alert_box.style.top = scrollOffsets.top + (winDimensions.height / 2) + "px";// + scrollOffsets.top - (messageBoxHeight / 2) + "px";
        alert_box.style.marginTop = "-" + (messageBoxHeight / 2) + "px";
    }
    Element.update('alert_message_header', header);
    Element.update('alert_message_text', message);
    mask.style.height = winDimensions.height + scrollOffsets.top + "px";
    mask.style.width = winDimensions.width + scrollOffsets.left + "px";
    alert_box.style.top = scrollOffsets.top + (winDimensions.height / 2) + "px";
    $('alert_box').style.display = "block";
    $('close_link').focus();
}

function showLoadingIndicator() {
    Element.update('alert_message_text', '<img src="/images/global/loading.gif"/> Loading...');
    $('alert_box').style.display = "block";
}

function closeAlert() {
    $('alert_box').style.display = "none";
}

function larger() {
    objCenter = $('content');
    objSize = objCenter.style.fontSize.replace(/px/, "");
    if (objSize == "") {
        objSize = 12;
    }
    objSize++;
    objCenter.style.fontSize = objSize + "px";
}

function smaller() {
    objCenter = $('content');
    objSize = objCenter.style.fontSize.replace(/px/, "");
    if (objSize == "") {
        objSize = 13;
    }
    objSize--;
    objCenter.style.fontSize = objSize + "px";
}


function togglePodView(clickedElement) {
    podElementID = Element.nextSiblings(clickedElement.parentNode)[0];
    if ($(podElementID).style.display == "none") {
        Effect.BlindDown(podElementID, {duration: 0.5});
        Element.update(Element.firstDescendant(clickedElement), "&ndash;");
    }
    else {
        Effect.BlindUp(podElementID, {duration: 0.5});
        Element.update(Element.firstDescendant(clickedElement), "+");
    }
}

function submitToAutoHome(strValue) {
    if (strValue != "") {
        window.location.replace(strValue);
    }
    else {
        alert('Please make a selection from the list.');
    }
}


function doCompare(objId) {
    Element.update(objId, "Comparison Complete");
}

function noMoreThanThree(formName) {
    args = Form.serialize(formName);
    splitArgs = args.split('&');
    if (splitArgs.length > 4) {
        alert("You can view a maximum of 3 plans at once. Please uncheck a plan.");
        return false;
    }
    else if (splitArgs.length == 0) {
        return false;
    }
    return true;
}


function getMedicareEligible(blnMedicare, prms) {
    //this gets the 3rd question if the previous 2 questions indicate medicare
    if (prms.indexOf("classification=") != -1) {
        Element.update("results", "");
        if (blnMedicare == true) {
            Element.update('medicare_coverage', '<img src="/images/global/loading.gif"/>  Loading, please wait...');
            new Ajax.Updater('medicare_coverage', '/pebb/get_medicare_eligible', {
                asynchronous: true,
                evalScripts: true,
                parameters: prms
            });
            //$('find_button').disabled = true;
            $('medicare_coverage').style.display = "block";
        }
        else {
            Element.update('medicare_coverage', '<img src="/images/global/loading.gif"/>  Loading, please wait...');
            new Ajax.Updater('medicare_coverage', '/pebb/get_states', {
                asynchronous: true,
                evalScripts: true
            });

            //$('find_button').disabled = false;
            Element.show('medicare_coverage');
        }
    }
}



function PebbRequest(objId, page, params) {
    Element.update(objId, '<img src="/images/global/loading.gif"/> Loading, please wait...');
    new Ajax.Updater(objId, '/pebb/' + page, {onLoading: 'showLoadingIndicator()',onComplete: 'closeAlert()',parameters: params, asynchronous:true, evalScripts: true});
}

function toggleDifferentBenefits(val){
    trs = $$('tr.same_benefit)');
    for (i = 0; i < trs.length; i++) {
        if (val == true) {
            trs[i].style.display = "none";
        }
        else {
            if (navigator.appVersion.indexOf("MSIE") != -1) { //IE cant handle table-row display value
                trs[i].style.display = "block";
            }
            else {
                trs[i].style.display = "table-row";
            }
        }
    }
}

function toggleView(objId) {
	objElement = document.getElementById(objId);
	if (objElement.style.display == "none") {
		objElement.style.display = "block";
	}
	else {
		objElement.style.display = "none";
	}
}

