﻿function clearText( id, defaultText ){
    if( document.getElementById(id).value == defaultText ){
        document.getElementById(id).value = "";
    }
}

function addText( id, defaultText ){
    if( trim( document.getElementById(id).value) == "" ){
        document.getElementById(id).value = defaultText;
    }
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function verifyCheckBox(checkBoxId,focusId) {
    var oCheckBox = document.getElementById(checkBoxId);
    var oButton = document.getElementById(focusId);
    if(oCheckBox.checked) {
        oButton.focus();
    }
}

var popupList = {};
function openWindow( winName, url, w, h, scroll, resize) {

    if((typeof(resize)=='undefined')){
        resize = 0;
    }
	//  Close other instances of this window.
	if ( popupList[winName] != null && typeof( popupList[winName] ) == "object" && !popupList[winName].closed ) {
		popupList[winName].close();
		popupList[winName] = null;
	}

	//  Setup the new window.
	popupList[winName] = window.open( url, winName, "height=" + h + ",width=" + w + ",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=" + resize + ",scrollbars=" + scroll + ",status=1,toolbar=0","pop" );

	//  Open the window.
	if ( popupList[winName].opener == null ) {
		popupList[winName].opener = window;
	}
	if ( navigator.appName == 'Netscape' ) {
		popupList[winName].focus;
	}
}

function disableHistory(){
    window.history.forward();
    if(window.history.forward(1) != null) {
        window.history.forward(1);
    }
}

function CaptureEnterKey()
    {   
        if(event.keyCode == 13)
        {         
            window.event.returnValue=false; 
            window.event.cancel = true; 
            document.form1.btnLogin.click(); 
        }
    }

function captureEnterKeyNew(e, btnId) {
    var key;

    if (window.event) {
        key = window.event.keyCode;
    }
    else {
        key = e.which;
    }

    if (key == 13) {
        var btn = document.getElementById(btnId);
        if (null != btn) {
            btn.click();
            event.keyCode = 0;
        }
    }
}

function captureSearches(e, btnId, btn2Id) {
    var btn1 = document.getElementById(btnId);
    if (null != btn1) {
        captureEnterKeyNew(e, btn1.Id);
    } else {
        var btn2 = document.getElementById(btn2Id);
        if (null != btn2) {
            captureEnterKeyNew(e, btn2.Id);
        }
    }
}
    
function captureEnter(e, id, formId){

    if(e.keyCode == 13)
    {
        var btn = document.getElementById(id);
        if(null != btn){
            if(!btn.disabled){
               btn.click();
            }
        }
    }
}
    
    function showRules(contestID, path)
    {   
        if (window.showModalDialog) 
        {
            window.showModalDialog(path + '?contestid=' + contestID,'name','height=700,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,modal=yes');
        }
        else
        {
            window.open( path + '?contestid=' + contestID,'name','height=700,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,modal=yes');
        }
        
    }
    
    function showHideMAPD(id1,id2)
    {
        document.getElementById(id1).style.display = 'none';
        document.getElementById(id2).style.display = 'block';
    }

    function checkState(id,planId,azId) {
        var cont = true;
        var cboState = document.getElementById(id);
        var hfPlanType = document.getElementById(planId);
        var cboPlan = document.getElementById(azId);

        if (hfPlanType.value == 'Medical' && cboState.value == 'AZ' && cboPlan.value == 'AZ') {
            confirm('You will now be redirected to the Arizona Foundation for Medical Care provider search.\nContinue?');
        
        }
        else {
            if (hfPlanType.value == 'Medical' && cboState.value != 'UT') {
                cont = confirm('Not all plans provide a Participating Provider benefit for providers outside of Utah. Please call customer service at (800) 662-5851 to confirm out-of-state medical benefits.\nDo you wish to continue your search?');
                if (!cont) {

                    for (var i = 0; i < cboState.options.length; i++) {
                        if (cboState.options[i].value == 'UT') {
                            cboState.options[i].selected = true;
                            return;
                        }
                    }

                }
                //            else {
                //                window.location = "http://www.beechstreet.com/beechplus/IPLU/Control?hJSPName=splash.jsp&hButtonMode=Search";
                //            }
            }
        }

    }

    function toggleLayer(whichLayer) {
        var elem, vis;
        if (document.getElementById) // this is the way the standards work
            elem = document.getElementById(whichLayer);
        else if (document.all) // this is the way old msie versions work
            elem = document.all[whichLayer];
        else if (document.layers) // this is the way nn4 works
            elem = document.layers[whichLayer];
        vis = elem.style;
        // if the style.display value is blank we try to figure it out here
        if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
            vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
        vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';

        if (vis.display == 'block') {
            x = event.clientX + document.body.scrollLeft -150;
            y = event.clientY + document.body.scrollTop - 150;

            vis.left = x;
            vis.top = y;
        }
    }


    function showReport(groupNumber, reportName) {
        window.open('reports/report.aspx?groupNumber=' + groupNumber + '&reportName=' + reportName, 'name', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no');
    } 
