// JavaScript Document

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

window.onload = externalLinks;

/**********************************************************************/
// remove special character like "?" 
function filterNum(str) 
{
          var re = /\?/g;          
          return str.replace(re, "");
}

/**********************************************************************/
function Trim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
/**********************************************************************/
// Submit/Redirect to the FluTracker page
function GoFluTracker(txtBoxId) {

	var zipCode = document.getElementById(txtBoxId).value;				
	document.location = "/hcp/flu-surveillance-results/default.aspx?zip=" + zipCode;
	return false;	
}
/**********************************************************************/
// Verify search request
function IsValidSearchRequest() {

	var searchBox = document.getElementById("searchBox");
	var strQuery = Trim(searchBox.value);
	var strGoogleQuery = filterNum(strQuery)
	var reNonSpace = /\S/g;
	var rex = /[^a-zA-Z ]/;  

	if(reNonSpace.test(strGoogleQuery)) {
		if (strGoogleQuery.match(rex)) {	     
			alert("Please enter a question and click 'Go'.");
			searchBox.focus();
			return false;      
		}  		
	} else {
			alert("Please enter a question and click 'Go'.");
			searchBox.focus();
			return false;   
	} 
	
	return true;  
}
/**********************************************************************/
// Submit/Redirect to the HCP search page
function GoHCPSearch() {
	// Verify search request
	if (!IsValidSearchRequest()) return false;

	var searchFor = document.getElementById("searchBox").value;				
	document.location = "/hcp/search.aspx?q=" + searchFor;
	
}
/*********************************************************************/
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.	 
function doClick(e) {
   
    var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
		
    if (code == 13) {	
			if (e.cancelable) {
				e.preventDefault();							
			}else {			
				e.keyCode=0;			
			}
			GoHCPSearch();			
      }          
} 
/**********************************************************************/
// Print a page
function PrintPage() {

	if(window.print) {
		window.print();
	} else {
		alert("Please use File | Print to print this page.");
	}
	return false;
}
/**********************************************************************/