

// original: http://www.uptodate.com/patient_search_box.js?widgetId=1&clientId=544E537FBB9B4931

//<meta name="decorator" content="none"/>

//Add an onload event onto the window
function onloadAdd(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
	    					oldonload();
	    					func();
	    				}
	}
}

function validate() {
  var objSearch = document.getElementById("txtSearch");
  if (objSearch) {
    var searchTerm = objSearch.value;
    if (objSearch.defaultValue != searchTerm && searchTerm != "") {
      var url = document.getElementById("searchUrlBase").value;
      url += '?source=' + document.getElementById("utdSource").value;
      url += '&utm_campaign=' + document.getElementById("_CAMPAIGN").value;
      url += '&utm_medium=' + document.getElementById("_MEDIUM").value;
      url += '&utm_source=' + document.getElementById("_SOURCE").value;
      url += '&referer=' + document.getElementById("_REFERER").value;
      if (document.getElementById("widgetClientId")) {
        url += '&widgetClientId=' + document.getElementById("widgetClientId").value;
      }
      url += '&search=' + encodeURIComponent(searchTerm);
      window.open(url, '_blank');
    }
	}
}

function clearText(field){
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
}

// Make sure our search text box acts as if the Go button was pressed, and does not
// submit the form it is on, if any.
function handleEnter(e) {
  var key = (window.event) ? window.event.keyCode : e.which;
  if (key == 13) {
    validate();
    return false;     
  }
  else {
    return true;     
  }
}

function showDiv() {
// intentionally do nothing.  This supported legacy widget TOC show/hide, and can be removed
// when we no longer support the legacy widget.
}

function beginHideDiv() {
// intentionally do nothing.  This supported legacy widget TOC show/hide, and can be removed
// when we no longer support the legacy widget.
}

function hideDiv() {
// intentionally do nothing.  This supported legacy widget TOC show/hide, and can be removed
// when we no longer support the legacy widget.
}

function pageLoad() {
	var jsonObj = {"widgetCode":"\r\n\r\n<input name=\"search\" type=\"text\" id=\"txtSearch\" onfocus=\"clearText(this)\" onblur=\"clearText(this)\" onkeypress=\"return handleEnter(event);\" style=\"width:104px; background-color: #ffffcc; font-family: Arial, Helvetica, sans-serif; font-size: 9px; margin-bottom: 5px; padding: 2px; color: #666666;\"\r\nvalue=\"Search health topics\"/>&nbsp;\r\n<input type=\"button\" value=\"Go\" style=\"font-family: Arial, Helvetica, sans-serif; font-size: 9px; margin-bottom: 5px; color: #666666; height:18px;\" onclick=\"validate();\"/>\r\n\r\n<input type=\"hidden\" id=\"widgetClientId\" name=\"widgetClientId\" value=\"420949AD3CE63125\"/>\r\n\r\n<input type=\"hidden\" id=\"utdSource\" name=\"source\" value=\"PATIENT_SEARCHBOX\"/>\r\n<input type=\"hidden\" id=\"_REFERER\" name=\"referer\" value=\"\"/>\r\n<input type=\"hidden\" id=\"_CAMPAIGN\" name=\"utm_campaign\" value=\"widget1\"/>\r\n<input type=\"hidden\" id=\"_MEDIUM\" name=\"utm_medium\" value=\"widget\"/>\r\n<input type=\"hidden\" id=\"_SOURCE\" name=\"utm_source\" value=\"widget\"/> \r\n<input type=\"hidden\" id=\"searchUrlBase\" value=\"http://www.uptodate.com/patients/content/search.do\"/>\r\n"};

	try {
		if (jsonObj.widgetCode) {
			var objContainer = document.getElementById("uptodatesearchcontainer");
			if (objContainer) {
// embedded in page already
				objContainer.innerHTML = jsonObj.widgetCode;
			}
  	}
	} catch (e) {
		//ignore
	}
	
  // set referer
  var objReferer = document.getElementById("_REFERER");
  if (objReferer) {
    objReferer.value = window.location.href;
  }
}

onloadAdd(pageLoad);