
//called in ajax call to populate programs
//this allows me to submit form when enter is pressed for program dropdown list
function submitform(){
		document.fap.submit();
}


//called in ajax call to populate programs
//this allows me to submit form when enter is pressed for program dropdown list
function submitProgram(){
	if (event.keyCode == 13) 
	{
		document.theForm1.submit();
	}
}
function changeProgramRadio()
{
	changeRadio(document.theForm1.searchType[2]);
}
///--------///

function hideElement (elementId) {
	var element;

	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	if (element && element.style)
		element.style.display = 'none';
}
function hideAjaxElement (elementId) {
	var element;
	////alert('hideAjaxElement');
	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	
	if (element && element.style)
		element.style.display = 'none';

	clearText(element);		
}
function showElement (elementId) {
	var element;
	
	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	if (element && element.style)
		element.style.display = '';
}

function showAjaxElement(elementId,webServiceId)
{
	//alert('showAjaxElement');
	var element;

	if (document.all)
		element = document.all[elementId];
	else if (document.getElementById)
		element = document.getElementById(elementId);
	
	if (element && element.style)
		element.style.display = '';
	
	clearText(element);

	var requestEvents = "";
  	requestEvents=createRequest(requestEvents);
  	processRequest(requestEvents,"<%=url1%>", webServiceId, "processEvents(request.responseXML)");
	
		
}

function showHide(theSelect) {
	if(theSelect.options[theSelect.selectedIndex].value == 'Any') {
		hideAjaxElement('wbPrg');
		hideElement('wbPrgSpacer');
	}
	else
	{
		hideAjaxElement('wbPrg');
		showAjaxElement('wbPrg', theSelect.options[theSelect.selectedIndex].value);
		showElement('wbPrgSpacer');
	}
	// and so on
}

function lNameSearch(letter) {
    document.theForm1.fpType.value="lName";
	document.theForm1.lastName.value=letter;
    document.theForm1.submit();
	return true;
}

function changeRadio(el){
    //el.checked = el.checked ? false : true;
	if(el.checked==false)
		el.checked=true;

    return true;
}

function clearOtherSearch(type)
{
	////alert('clearOtherSearch');
	////alert(type);
	if(type=='name')
	{
		if(document.theForm1.filter.value!='')
		{
			initializeField();
		}
		document.theForm1.specialty.options.value="";
		document.theForm1.webServiceSlt.options.value="";
		hideAjaxElement('wbPrg');
		document.theForm1.clnInterestSlt.options.value="";
	}
	else if(type=='webservice')
	{
		if(document.theForm1.filter.value!='')
		{
			initializeField();
		}		
		document.theForm1.lastName.value="";
		document.theForm1.firstName.value="";
		document.theForm1.specialty.options.value="Any";
		document.theForm1.clnInterestSlt.options.value="Any";

	}
	else if (type=='interest')
	{
		document.theForm1.lastName.value="";
		document.theForm1.firstName.value="";
		document.theForm1.specialty.options.value="Any";
		document.theForm1.webServiceSlt.options.value="Any";
		hideAjaxElement('wbPrg');
	}
	else if(type=='specialty')
	{
		if(document.theForm1.filter.value!='')
		{
			initializeField();
		}		
		document.theForm1.lastName.value="";
		document.theForm1.firstName.value="";
		document.theForm1.webServiceSlt.options.value="Any";
		hideAjaxElement('wbPrg');
		document.theForm1.clnInterestSlt.options.value="Any";
	}
}


//called in ajax call to populate programs
//this allows me to submit form when enter is pressed for program dropdown list
function submitform(){
		document.theForm1.submit();
}


//must define request within the page to allow for asycronous requests between multiple obj

function createRequest(request) {
//	alert('createRequest');
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = null;
    }
  }
}

if (request == null)
  //alert("Error creating request object!");

return request;
}

function processRequest (request, url, webServiceId, processData) {
	//alert(url);
	//url="http://swvlxdevpprev1.swmed.edu/utsw-ext-templating/org/jsp/update_programs_xml.jsp";
    	var currentTime = new Date();
	request.open("GET", url+"?currDate="+currentTime+"&webServiceId="+webServiceId, true);
	request.onreadystatechange=function()
	  {
        if(request.readyState == 4)
		{
		  //////
		  if(request.status == 200) 
		  {
		  ////alert(processData);
	 	     eval(processData);
		  }
		  /////
        }
       }    
 
	request.send(null);
}

function processHomeRequest (request, url, processData) {

    var currentTime = new Date();
	request.open("GET", url+"?currDate="+currentTime, true);
	request.onreadystatechange=function()
	  {
        if(request.readyState == 4)
		{
		  //////
		  if(request.status == 200) 
		  {
	 	     eval(processData);
		  }
		  /////
        }
       }    
 
	request.send(null);
}


function processEvents(obj)
{  
	//alert('processEvents');
		var eventstmp=document.getElementById("wbPrg"); 
		clearText(eventstmp);
		if(obj!=null)
		{
			var program = obj.getElementsByTagName('program');
			if(program!=null)
			{
				var programIdTmp = obj.getElementsByTagName("programId0")[0].firstChild.nodeValue;
				
				//only build (tr) body if programId="A0A" : no programs for this webservice
				if(programIdTmp!='A0A')
				{
		
					//nodes for select box			
					var cell = document.createElement("td");
					cell.setAttribute("colspan","2");
					cell.className="findPhysicianInputBGb";
					var cellText = document.createTextNode('\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0');
					cell.appendChild(cellText);
					
					var cell2 = document.createElement("td");
					cell2.setAttribute("align","right");
					var label = document.createElement("label");
					label.setAttribute("for", "webProgram");
					label.setAttribute("accesskey", "p");
					
					var selectBox="";
					selectBox=document.createElement("select");
					selectBox.setAttribute("id","webProgramSlt");
					selectBox.setAttribute("name","webProgramSlt");
					
					//selectBox.setAttribute("onClick","changeRadio(document.theForm1.searchType[2]);")
		
					if (selectBox.addEventListener){
					  selectBox.addEventListener('click', changeProgramRadio, false); 
					} else if (selectBox.attachEvent){
					  selectBox.attachEvent('onclick', changeProgramRadio);
					}
		
					if (selectBox.addEventListener){
					  selectBox.addEventListener('keyup', submitProgram, false); 
					} else if (selectBox.attachEvent){
					  selectBox.attachEvent('onkeyup', submitProgram);
					}
		
					
					selectBox.className="selectOne";
					
					var optionBox=document.createElement("option");
					optionBox.setAttribute("value", "Any");
					//optionBox.setAttribute("selected", "selected");
					//optionBox.className="findPhysicianDDB";
					var optionText = document.createTextNode("Select a Medical Program");
					optionBox.appendChild(optionText);			
					
					selectBox.appendChild(optionBox);			
		
					   	for (loop = 0; loop < program.length; loop++) 
					   	{
						   	var programId = obj.getElementsByTagName("programId"+loop)[0].firstChild.nodeValue;
			
							var programName =obj.getElementsByTagName("programName"+loop)[0].firstChild.nodeValue; 
			
							var optionBox2=document.createElement("option");
							optionBox2.setAttribute("value", programId);
							optionBox2.className="findPhysicianDDB";
							var optionText2 = document.createTextNode(programName);
							optionBox2.appendChild(optionText2);
							selectBox.appendChild(optionBox2);
							
						}		
					
					label.appendChild(selectBox);
					cell2.appendChild(label);
					
					var events=document.getElementById("wbPrg"); 
					clearText(events);
					events.appendChild(cell);		
					events.appendChild(cell2);
				}
			}
		}	

 } 


function getNewKeywords(textObj) {
  //var url = "http://www.utsouthwestern.edu/utsw/ccw/physiciansearch/keywordtran/0,,,00.html";
  var url = "/utsw-ext-templating/org/jsp/ccwphysiciansearchkeywordtran.jsp";
  //var url = "/utsw-ext-templating/org/jsp/ccw%20physician%20search%20keyword%20tran.jsp";
  url = url + "?dummy=" + new Date().getTime();
  url = url + "&keywordQuery="+textObj.value
  //var requestEvents = "";
  //	requestEvents=createRequest(requestEvents);
  	
try {
  request = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      request = null;
    }
  }
}

if (request == null)
  alert("Error creating request object!");
  
  //if(textObj.value.length>1) {  
  request.open("GET", url, true);
  request.onreadystatechange = updatePage;
  request.send(null);
// }
}



function updatePage() {
  if (request.readyState == 4) {
    if (request.status == 200) {
      var responseData = request.responseText;
      var htmlSelectBoxDiv = document.getElementById("keywordList");
      //alert(responseData);
      htmlSelectBoxDiv.innerHTML=responseData
      } else {
      var message = request.getResponseHeader("Status");
      if ((message.length == null) || (message.length <= 0)) {
        //alert("Error! Request status is " + request.status);
      } else {
        //alert(message);
      }
    }
  }
}

function initializeField() {
document.theForm1.filter.value='   ';
getNewKeywords(document.theForm1.filter);
document.theForm1.filter.value='';

}
function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}

function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}




