/* Default Physician Directory setting TomTest*/
var specialty=13;

/* Default Newsletter settings */
var moduletype=3;
var newsletter=24;

/* brings in date for header */
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
}
wmd_today =  months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear()));

/* function to change a class */
function setClass(objectID,newClass) {
	var object = document.getElementById(objectID);
	if (object) {
		object.className = newClass;
	}
}

/* function to toggle visibility */
function toggle( targetId, signId ) {
   if ( document.getElementById ) {
    target = document.getElementById( targetId );
	if (signId != '') {sign = document.getElementById( signId );}
    if ( target.style.display == "none" ) {
     target.style.display = "";
	 if (sign) {sign.src = sign.src.replace('plusSign','minusSign');}
    } else {
     target.style.display = "none";
	 if (sign) {sign.src = sign.src.replace('minusSign','plusSign');}
    }
   }
}

/* function to add an onload event */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } else 
    {
       window.onload = function() 
    {
      oldonload();
      func();
    }
  }
}	

/* function to go back to previous page */
function timedReturn()
	{
	var t=setTimeout("history.go(-1)",60000)
	}

/* function to check e-mail address validity on a form */
 function checkEmailAddr() 
 {
  illegal = /[^\w._\-]/;
  email = document.newsletterForm.EmailAddr.value;

  if (email.length<6 || email.indexOf("@")==-1 || email.indexOf('.')==-1)
  { email=""; }
  else 
  {
   At = email.indexOf("@");
   Period = email.lastIndexOf('.');
   DNS1 = email.substring(0,At);
   if (DNS1.length<1 || DNS1.match(illegal)!=null) email="";
   DNS2 = email.substring(At+1,Period);
   if (DNS2.length<1 || DNS2.match(illegal)!=null) email="";
   DNS3 = email.substring(Period+1,email.length);
   if (DNS3.length<2 || DNS3.match(illegal)!=null) email="";
  }

  if (email.length==0) 
  {
   alert("The email address you have entered is invalid. Please re-enter a valid email address.\n");
   document.newsletterForm.eMail.focus();
   return false;
  }
  
  return true;
 }
 
/* function for omniture tracking */
function sl(url, link_type, bi_tag)
{
	var href = new String(url.href);
	
	// used for Omniture Tracking
	// Figures out if the page has webmd3. For the other external webmd owned assets, they already have biscripts to pull the cookie
	if (href.indexOf("webmd3") == -1) {
		ctrs(bi_tag);
	}
	else {
		wmdPageLink(bi_tag);
	}	

	var status,toolbar,width,height,resizable,scrollbars,menubar;
	
	var left = 0;
	var top = 0;

	if (href.indexOf("/video/") != -1) {
		width=860;
		height=730;
		top=1;
		left=1;
		scrollbars="no";
		resizeable="no";
		status="yes";
		left = 5;
		top = 5;
	}
	else 
		if (href.indexOf("/healthmanager.") != -1) {
			return openAssessPopup(url);			
		}
		else
			if ((href.indexOf("/content/article") != -1 || href.indexOf("/content/pages") != -1 || href.indexOf("/solutions") != -1 || href.indexOf("/content/Article") != -1 || href.indexOf("/content/Pages") != -1) && (link_type != 'sp')) {
				return true; // don't do anything
			}
			else 
				if(link_type == '' || link_type == 'normal' || link_type == 'regular')
				{
					return true; // don't do anything
				}
				else if(link_type == 'sp')
					{
					   width = 590;
					   height = 400;
					   toolbar = 0;
					   resizable = 1;
					   status = 0;
					   scrollbars = 1;
					   left = 5;
					   top = 5;
					}
					else
						if(link_type == 'ai')
						{
						   width = 715;
						   height = 600;
						   scrollbars = 1;
						   toolbar = 0;
						   resizable = 1;
						   status = 0;
						   left = 5;
						   top = 5;
						}
						else
							if(link_type == 'nw')
							{
								// just open a new window
								//window.open(url);
								//return false;
							   width = 1000;
							   height = 600;
							   scrollbars = 1;
							   toolbar = 1;
							   resizable = 1;
							   status = 1;
							   left = 5;
							   top = 5;
							}
							else
								if(link_type == 'hw')
								{
							   		width = 526;
							   		height = 626;
							   		scrollbars = 1;
							   		toolbar = 1;
							   		resizable = 1;
							   		status = 1;
							   		left = 5;
							   		top = 5;
								}
								else
									{
									return true;
									}

	//alert(url);

	var newWindow = window.open(url,"","width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",scrollbars=" + scrollbars + ",toolbar=" + toolbar + ",resizable=" + resizable + ",status=" + status + ",menubar=" + menubar);
	
	//if(	moveWindow == true)
	//	newWindow.moveTo(XPosition,YPosition);

	return false;
}

//For the search bar
function  DoSearch(srchForm) {
	var query, sourceType, url, srchOmnitureValue;
	if (srchForm == undefined) { srchForm = "topSrchBar";}
	//get the query, set ctrs
	if (srchForm == "topSrchBar") {
		query = escape(document.getElementById("searchQuery_fmt").value);
		srchOmnitureValue = 'srch-bar_submit';
	} else if (srchForm == "botSrchBar") {
		srchOmnitureValue = 'srch-bar-foot_submit';
		query = escape(document.getElementById("searchQueryFoot_fmt").value);
	}
	
	if(query.length > 0) {
		try
		{
			ctrs(srchOmnitureValue);	//omniture function
		}
		catch(err)
		{
		}
		
		/* not sure if we still use sourceType for the chrome search, i believe this is left over from the tab search box - paolo */
		if (document.getElementById("sourceType")) {
			sourceType = document.getElementById("sourceType").value;
		}
		if(sourceType == "web_search") {
			window.location.href = "http://www.webmd.com/search/search_results/web_results.aspx?query=" + query + "&sourceType=" + sourceType;
		} else {
			window.location.href = "http://www.webmd.com/search/search_results/default.aspx?query=" + query + "&sourceType=" + sourceType;
		}
	} else {
		ctrs(srchOmnitureValue);
		window.location.href = "http://www.webmd.com/search";
	}
	return false;
}

function submitSearchBoxLanding(ev, srchForm) {
	if((ev.which && ev.which == 13) || (ev.keyCode && ev.keyCode == 13)) {
		return DoSearch(srchForm);
	} else {
		return true;
	}
}

// slider for the shared health tools module thats all over the site
function SwitchSlideHT(obj, pID){
	if(document.getElementById){
	var el = document.getElementById(obj);
	
	if (pID.indexOf("slide") != -1) {
		var slide = document.getElementById(pID);
		var slide_ar = ['htslide0','htslide1'];
	} 
	else {
		var sign = document.getElementById(pID);
		var sign_ar = ['htsign0','htsign1'];
	}
	
	var el_ar = ['htsub0','htsub1'];
	
		if(el.style.display == "none"){
			for (var i=0; i<el_ar.length; i++){
				document.getElementById(el_ar[i]).style.display = "none";
			}
			el.style.display = "block";
			
			if (sign) {
				for (var j=0; j<sign_ar.length; j++){
									document.getElementById(sign_ar[j]).src = "images/icn_plus.gif";
				}		
				sign.src = "images/icn_minus.gif";	
			}
			else {
				for (var j=0; j<slide_ar.length; j++){
									document.getElementById(slide_ar[j]).style.background = "url(images/htCenterSShadow.gif) repeat-x";
				}	
				slide.style.background = "none";
			}
		}
		else{
			el.style.display = "none";
			if (sign) {
			sign.src = "images/icn_plus.gif";
			}
			else {
			slide.style.background = "url(images/htCenterSShadow.gif) repeat-x";
			}
		}
	}
}

/* function for bookmarking */
function wmdDoBookmark() {
  /* for omniture tracking */
  wmdPageLink('bookmark');
  /* quick check of the browser and OS */
  var agt=navigator.userAgent.toLowerCase();

  /*** PLATFORM ***/
  var is_win = (agt.indexOf('windows')!=-1);
  var is_mac = (agt.indexOf('mac')!=-1);

  /*** BROWSER ***/
  var is_ie     = (agt.indexOf('msie') != -1);
  var is_firefox = (agt.indexOf('firefox') != -1);
  var is_netscape  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('compatible') == -1));
  var is_safari = ((agt.indexOf('safari')!=-1)&&(is_mac));

  if (is_win) {
    if (is_ie && window.external) {
      window.external.AddFavorite(location.href,document.title);
    }
    else {
      if (is_firefox) {
        alert('Please press CTRL + D to bookmark this page.');
      }
      else {
        if (is_netscape) {
          alert('Please press CTRL + D to bookmark this page.');
        }
        else {
          alert('Please press CTRL + D to bookmark this page.');
        }
      }
    }
  }
  else {
    if (is_mac) {
      if (is_ie && window.external) {
        window.external.AddFavorite(location.href,document.title);
      }
      else {
        if (is_safari) {
          alert('Please press Command (Apple) + D to bookmark this page.');
        }
        else {
          alert('Please press UP arrow + Command (Apple) + D to bookmark this page.');
        }
      }
    }
    else {
      alert('Please press CTRL + D to bookmark this page.');
    }
  }
  return false;
}

/* function for health solutions footer */
function isSensTop (priTop,secTop) {
	var isSensTopBool = false;


	if (priTop.charAt(0) == '7') {
		isSensTopBool = true;
	} else {
		var secTopArray = secTop.split("|");
		var curSecTop = 0;

		for (curSecTop in secTopArray) {
			if (secTopArray[curSecTop].charAt(0) == '7') {
				isSensTopBool = true;
				break;		
			}
		}
	}
	
	return isSensTopBool;
}

/* function for healthmanager portland popup */
function openAssessPopup(theUrl) { 
	var win = window.open(theUrl, 'WebMDHealthManagerTool','resizable,scrollbars,width=705,height=600,left=25,top=25,screenX=25,screenY=25'); 
	if (win) { win.focus(); } 
	return false;
}


/* functions for printer friendly articles - paolo */

/* Used to open a printer friendly window */
function printWindow() { 
var x = 800; var y = 600; 
	var url = location.href;

	if (url.search("[\\#]") != -1) {
		url = url.split("#")[0];
	}

	if (url.search("[\\?]") != -1) {
	url = url + '&print=true';
	} else {
	url = url + '?print=true';
	}

	if (navigator.appVersion.indexOf("Mac") > 0) { 
	openWindow(url, "width=" + x + ",height=" + y + ",toolbar=yes,resizable=yes,scrollbars=yes"); 
	} else { 
	openWindow(url, "width=" + x + ",height=" + y + "toolbar=1,location=1,directories=0,status=0,menubar=0,scrollbars=1,resize=yes,copyhistory=0,top=10,left=10"); 
	} 
} 

/* opens a window */
function openWindow(url, optionString) { 
	window.open(url, "printFriendly", optionString); 
} 

function getParam(name) {
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function remove(s, t) {
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + remove(s.substring(i + t.length), t);
  return r;
  }

/* insert/customize printer friendly elements in the top of the page */
function printElements() {
	/* swap with smaller print only logo -- keeping it inline because if its in the css as a background it might not print with user settings  */
	var logo = document.getElementById('logo_rdr').getElementsByTagName('img')[0];
	logo.src = image_server_url + '/webmd/consumer_assets/site_images/layout/shared/logo_webmd_print.gif';
	logo.width = '190';
	logo.height = '43';
	logo.style.visibility = 'visible';
	
	var printDiv = document.createElement('div');
	printDiv.setAttribute('id','global-head-print');
	printDiv.innerHTML = '<a class=\"printWindow-button" href=\"#\" onclick=\"javascript:window.print();return sl(this,\'\',\'prnt\');"\"><img src="'+ image_server_url +'/webmd/consumer_assets/site_images/layout/shared/printWindow_button.gif" width="56" height="21" border="0" alt="Print"/></a><a class=\"printWindow-button" href=\"#\" onClick=\"javascript:window.close();\"><img src="'+ image_server_url +'/webmd/consumer_assets/site_images/layout/shared/closeWindow_button.gif" width="107" height="21" border="0" alt="Close Button"/></a></div>';
	
	if (!document.getElementById("ContentPane2")) return false;
	var insert1 = document.getElementById("ContentPane2");
	
	var urlDiv = articleUrl();

	var notesDiv = document.createElement('div');
	notesDiv.setAttribute('id','print_notes');
	notesDiv.innerHTML = '<div><a href=\"#mynotes\">Type in <strong>"My Notes"</strong> to add personal or doctor discussion notes before printing.</a></div>';
		
	insert1.appendChild(printDiv);
	insert1.appendChild(notesDiv);
	insert1.appendChild(urlDiv);
}

/* get article url */
function articleUrl () {
	/* remove print parameter */
	var url = window.location.href;
	var token = "?print=true";
	
	if (url.indexOf("&print") != -1) {
		token = "&print=true";
	}
	
	var ArticleUrl = remove(url, token);
	
	var urlDiv = document.createElement('div');
	urlDiv.setAttribute('id','url_reference');
	urlDiv.innerHTML = '<div>Article Link:<span class="art_link"> '+ ArticleUrl +'</span></div>';
	return urlDiv;
}

/* execute if printerfriendly */

var pf_param = getParam("print");

/* Makes the nav work in IE */
sfHover = function() {
	if (document.getElementById("nav_fmt")) {
	var sfEls = document.getElementById("nav_fmt").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
/* Slide Switcher for Video Module */
function SwitchSlide(obj, pID){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("video").getElementsByTagName("div");
	var sign = document.getElementById(pID);
	var sign_ar = ['sign0','sign1', 'sign2', 'sign3', 'sign4'];
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
			for (var j=0; j<sign_ar.length; j++){
				document.getElementById(sign_ar[j]).src = "images/icn_plus.gif";
			}
			sign.src = "images/icn_minus.gif";
		}else{
			el.style.display = "none";
			sign.src = "images/icn_plus.gif";
		}
	}
}
