﻿$.ajaxSetup({
    xhr: function() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        }
        else {
            var progIDs = ['Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];

            for (var i = 0; i < progIDs.length; i++) {
                try {
                    var xmlHttp = new ActiveXObject(progIDs[i]);
                    return xmlHttp;
                }
                catch (ex) {
                }
            }

            return null;
        }
    }
});


$(document).ready(function() {

    //the div 'modal' is in the master page
    $myWindow = $('#modal');
    //instantiate the dialog
    
    $myWindow.dialog({ height: 400,
        width: 700,
        modal: true,
        position: 'center',
        autoOpen: false,
        title: '',
        overlay: { opacity: 0.5, background: 'black' }
                , bgiframe: true
    });

});

function showDescription() {


    fillContainer('modal', 'DescriptionDisplay.aspx');
    showModal('Measure Descriptions');
    return false;
}

function showKey() {

    fillContainer('modal', 'KeyDisplay.aspx');
    showModal('How To Read These Graphs');
    return false;
}

function showProviderDescription() {
    fillContainer('modal', 'ProviderDescription.aspx');
    showModal('Facility Type Descriptions');
    return false;
}

function showModal(title) {

    $myWindow.dialog('option', 'title', title);
    $myWindow.dialog("open"); $myWindow.show();
}

function hideModal() {
    $myWindow.hide();
    $myWindow.dialog("close");
}

function fillContainer(container, url) {
    var con2 = document.getElementById(container);

    if (url.toString().indexOf('?') > -1)
        url += "&nocache=" + new Date().toString()
    else
        url += "?nocache=" + new Date().toString()
    $.ajax(
        { type: "GET",
            url: url,
            success: function(data) {
                if (con2 == null) {
                    alert('Cannot find container, check case on control name, ensure that you are using defer=defer, place the script at the end of the page and use $(document).ready');
                }
                try {
                    $("#" + container).html('');
                    
                    $("#" + container).html(data);

                }
                catch (e) {
                    con2.innerHTML = "Error with <br/>" + url + "<br/><br/>" + e.name + "<br/>" + e.message;
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {

                var ret = "Error with <br/>" + url + "<br/><br/>" + textStatus + "<br/>" + errorThrown + "<br/>" + XMLHttpRequest.responseText;
                //con2.innerHTML = ret;
                $("#" + container).html(ret);


            },
            timeout: 300000
        }
    )
}
    $(document).ready(function() {
        $(".chartDiv").mouseover(function() { $(this).addClass("ui-state-hover") });
        $(".chartDiv").mouseout(function() { $(this).removeClass("ui-state-hover") });

        //This is to stop the Short Term header from receiving the alt tag. 
        var y = $("h3") ;
        if (y != null && y.length >=2 && y[1].parentNode != null && y[1].parentNode.parentNode != null)
        {
            var x = $(y[1].parentNode.parentNode);
            if (x.attr("class") == "chartChildDivAlt ui-widget")
            {
                x.attr("class", "chartChildDiv ui-widget");
            }            
        }
    });
    function toggleDisplay(id) {


        //debugger;
        $("#" + id).toggle("blind");



    }
    
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}