var win = null;
function NewWindow2(mypage,myname,scroll,w,h){
//alert (mypage)
//w = 570
//h = 550
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	if (window.showModalDialog) {
	 // win = window.showModelessDialog(mypage,myname,settings);
	  win = window.open(mypage,myname,settings);
	} else {
	  win = window.open(mypage,myname,settings);
	}
	win.focus()
}
function setval(formName, radioVal){
	if(formName == 'Hosp'){
		//document.Form1.ct.value = radioVal
		document.getElementById("ct").value = radioVal
	}
}
function switchDiv2(div_id)
{
if(div_id=='layer0'){
alert("Select a measure")
document.Form1.measures.focus()
}else{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    //hideAll();
    //changeObjectVisibility(div_id,"visible");
    if (style_sheet.display=="block"){
    changeObjectVisibility(div_id,"none"); 
    document.getElementById("hospHideLabel").innerHTML="Show Hospital Info";
    }else{
    changeObjectVisibility(div_id,"block");   
    document.getElementById("hospHideLabel").innerHTML="Hide Hospital Info"; 
    }
  }
  else 
  {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
 }
}
function switchDiv(div_id)
{
if(div_id=='layer0'){
alert("Select a measure")
document.Form1.measures.focus()
}else{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    hideAll();
    //changeObjectVisibility(div_id,"visible");
    changeObjectVisibility(div_id,"block");    
  }
  else 
  {
    alert("sorry, this only works in browsers that do Dynamic HTML");
  }
 }
}

// function hideAll()
//  hides a bunch of divs
//
function hideAll()
{
   //changeObjectVisibility("layer1","hidden");
   //changeObjectVisibility("layer2","hidden");
   //changeObjectVisibility("layer3","hidden");
   //changeObjectVisibility("layer4","hidden");
   
   changeObjectVisibility("layer1","none");
   changeObjectVisibility("layer2","none");
   changeObjectVisibility("layer3","none");
   changeObjectVisibility("layer4","none");
   changeObjectVisibility("layer5", "none");
   changeObjectVisibility("layer6", "none");
}

// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	//styleObject.visibility = newVisibility;
	styleObject.display = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}
//AJAX Functions:::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::::
function SetValue()
{
	var selectedvalue = document.Form1.measure.options[document.Form1.measure.selectedIndex].value
	//document.getElementById("Hidden2").value=selectedvalue;
	document.getElementById("Hidden2").value=selectedvalue
	
//}
return true;
}
var obj;
function GetDataViaAJAX()
{
	document.getElementById("measure").disabled=true;
	if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      obj = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      try
      {
      obj = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e)
      {
      try
      {
      obj = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e1)
      {
      obj = null;
      }
      }
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      //alert('Problem creating the XMLHttpRequest object');
       obj = null;
   } 
if(obj!=null)
{
var theURL = window.location.hostname
switch (theURL){
case "localhost":
var theLink = "http://localhost/MHQR/GetMeasure.aspx?mc="
break;
case "www.mha-apps.com":
var theLink = "http://www.mha-apps.com/mhqr/GetMeasure.aspx?mc="
break;
case "www.mnhospitalquality.org":
var theLink = "http://www.mnhospitalquality.org/GetMeasure.aspx?mc="
break;
case "www.mnhospitalquality.com":
var theLink = "http://www.mnhospitalquality.com/GetMeasure.aspx?mc="
break;
case "test.mnhospitalquality.org":
var theLink = "http://test.mnhospitalquality.org/GetMeasure.aspx?mc="
break;
}


   obj.onreadystatechange = ProcessResponse;
   obj.open("GET", theLink + document.getElementById("ct").value,  true);
   obj.send(null); 
   document.getElementById("measure").disabled=false;
          
}
return false;
}
function ProcessResponse()
{
	if(obj.readyState == 4)
	{
	
		if(obj.status == 200)
		{
		
		var dsRoot=obj.responseXML.documentElement;  
		var ddlOrders = document.getElementById("measure");
			//clear out list
			for (var count = ddlOrders.options.length-1;
			count >-1; count--)
			{
			ddlOrders.options[count] = null;
			}
		var orders =  dsRoot.getElementsByTagName('MeasureName');
		var myMC = dsRoot.getElementsByTagName('MeasureCode');
		var text; 
		
		var mc;
		var listItem;
		
		var myTmp;
		//get type of request for summary measure
		myTmp =getInnerText(myMC[0].childNodes[0]);
		var ValidChars = "0123456789.";
        var Char;
      	var myVar="";
        for (i = 0; i < myTmp.length; i++) 
            { 
            Char = myTmp.charAt(i);
            if (ValidChars.indexOf(Char) == -1) 
               {
               myVar +=myTmp.charAt(i);
               }else{
               break;
               }
            }
            //insert summary measure option with value from above
            //alert(myVar)
            switch(myVar)
            {
            case "SIP":
				break;
			case "CA":
			    break;
			case "SC":
			    break;
			default:
			listItem = new Option("Appropriate Care Measure",myVar,  false, false);
			listItem.style.backgroundColor="yellow";
			ddlOrders.options[ddlOrders.length] = listItem;			
			}
           	for (var count = 0; count < orders.length; count++)
			{
			mc =getInnerText(myMC[count].childNodes[0]);
			text =getInnerText(orders[count].childNodes[0]);
			listItem = new Option(text,mc,  false, false);
			ddlOrders.options[ddlOrders.length] = listItem;
			}
		}
		else
		{
		alert("Error retrieving data!" );
		}
	}
}
function getInnerText (node) {
  if (typeof node.textContent != 'undefined')
  {
    return node.textContent;
  }
  else if (typeof node.innerText != 'undefined')
  {
    return node.innerText;
  }
  else if (typeof node.text != 'undefined')
  {
    return node.text;
  }
  else
  {
    switch (node.nodeType)
    {
      case 3:
      case 4:
        return node.nodeValue;
        break;
      case 1:
      case 11:
        var innerText = '';
        for (var i = 0; i < node.childNodes.length; i++)
        {
          innerText += getInnerText(node.childNodes[i]);
        }
        return innerText;
        break;
      default:
        return '';
    }
  }
}
//END AJAX FUNCTIONS::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::