/*	SWFObject v2.0 rc1 <http://code.google.com/p/swfobject/>
	Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/

var swfobject=function(){var _1=[];var _2=[];var _3=null;var _4=null;var _5=false;var _6=false;var ua=function(){var _8=typeof document.getElementById!="undefined"&&typeof document.getElementsByTagName!="undefined"&&typeof document.createElement!="undefined"&&typeof document.appendChild!="undefined"&&typeof document.replaceChild!="undefined"&&typeof document.removeChild!="undefined"&&typeof document.cloneNode!="undefined";var _9=[0,0,0];var d=null;if(typeof navigator.plugins!="undefined"&&typeof navigator.plugins["Shockwave Flash"]=="object"){d=navigator.plugins["Shockwave Flash"].description;if(d){d=d.replace(/^.*\s+(\S+\s+\S+$)/,"$1");_9[0]=parseInt(d.replace(/^(.*)\..*$/,"$1"),10);_9[1]=parseInt(d.replace(/^.*\.(.*)\s.*$/,"$1"),10);_9[2]=/r/.test(d)?parseInt(d.replace(/^.*r(.*)$/,"$1"),10):0;}}else{if(typeof window.ActiveXObject!="undefined"){var a=null;var _c=false;try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_9=[6,0,21];a.AllowScriptAccess="always";}catch(e){if(_9[0]==6){_c=true;}}if(!_c){try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}}if(!_c&&typeof a=="object"){try{d=a.GetVariable("$version");if(d){d=d.split(" ")[1].split(",");_9=[parseInt(d[0],10),parseInt(d[1],10),parseInt(d[2],10)];}}catch(e){}}}}var u=navigator.userAgent.toLowerCase();var p=navigator.platform.toLowerCase();var _f=/webkit/.test(u);var _10=_f?parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):0;var ie=false;var win=p?/win/.test(p):/win/.test(u);var mac=p?/mac/.test(p):/mac/.test(u);/*@cc_on ie=true;@if(@_win32)win=true;@elif(@_mac)mac=true;@end@*/return {w3cdom:_8,playerVersion:_9,webkit:_f,webkitVersion:_10,ie:ie,win:win,mac:mac};}();var _14=function(){if(!ua.w3cdom){return;}addDomLoadEvent(main);if(ua.ie&&ua.win){try{document.write("<script id=__ie_ondomload defer=true src=//:></script>");var s=document.getElementById("__ie_ondomload");if(s){s.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);callDomLoadFunctions();}};}}catch(e){}}if(ua.webkit&&typeof document.readyState!="undefined"){_3=setInterval(function(){if(/loaded|complete/.test(document.readyState)){callDomLoadFunctions();}},10);}if(typeof document.addEventListener!="undefined"){document.addEventListener("DOMContentLoaded",callDomLoadFunctions,null);}addLoadEvent(callDomLoadFunctions);}();function callDomLoadFunctions(){if(_5){return;}if(ua.ie&&ua.win){var s=document.createElement("span");try{var t=document.getElementsByTagName("body")[0].appendChild(s);t.parentNode.removeChild(t);}catch(e){return;}}_5=true;if(_3){clearInterval(_3);_3=null;}var dl=_1.length;for(var i=0;i<dl;i++){_1[i]();}}function addDomLoadEvent(fn){if(_5){fn();}else{_1[_1.length]=fn;}}function addLoadEvent(fn){if(typeof window.addEventListener!="undefined"){window.addEventListener("load",fn,false);}else{if(typeof document.addEventListener!="undefined"){document.addEventListener("load",fn,false);}else{if(typeof window.attachEvent!="undefined"){window.attachEvent("onload",fn);}else{if(typeof window.onload=="function"){var _1c=window.onload;window.onload=function(){_1c();fn();};}else{window.onload=fn;}}}}}function main(){var rl=_2.length;for(var i=0;i<rl;i++){var id=_2[i].id;if(ua.playerVersion[0]>0){var obj=document.getElementById(id);if(obj){if(hasPlayerVersion(_2[i].swfVersion)){if(ua.webkit&&ua.webkitVersion<312){fixParams(obj);}}else{if(_2[i].expressInstall&&!_6&&hasPlayerVersion([6,0,65])&&(ua.win||ua.mac)){showExpressInstall(_2[i]);}else{displayAltContent(obj);}}}}createCSS("#"+id,"visibility:visible");}}function fixParams(obj){var _22=obj.getElementsByTagName("object")[0];if(_22){var e=document.createElement("embed");var a=_22.attributes;if(a){var al=a.length;for(var i=0;i<al;i++){if(a[i].nodeName.toLowerCase()=="data"){e.setAttribute("src",a[i].nodeValue);}else{e.setAttribute(a[i].nodeName,a[i].nodeValue);}}}var c=_22.childNodes;if(c){var cl=c.length;for(var j=0;j<cl;j++){if(c[j].nodeType==1&&c[j].nodeName.toLowerCase()=="param"){e.setAttribute(c[j].getAttribute("name"),c[j].getAttribute("value"));}}}obj.parentNode.replaceChild(e,obj);}}function fixObjectLeaks(){if(ua.ie&&ua.win&&hasPlayerVersion([8,0,0])){window.attachEvent("onunload",function(){var o=document.getElementsByTagName("object");if(o){var ol=o.length;for(var i=0;i<ol;i++){o[i].style.display="none";for(var x in o[i]){if(typeof o[i][x]=="function"){o[i][x]=function(){};}}}}});}}function showExpressInstall(_2e){_6=true;var obj=document.getElementById(_2e.id);if(obj){if(_2e.altContentId){var ac=document.getElementById(_2e.altContentId);if(ac){_4=ac;}}else{_4=abstractAltContent(obj);}var w=_2e.width?_2e.width:(obj.getAttribute("width")?obj.getAttribute("width"):0);if(parseInt(w,10)<310){w="310";}var h=_2e.height?_2e.height:(obj.getAttribute("height")?obj.getAttribute("height"):0);if(parseInt(h,10)<137){h="137";}var pt=ua.ie&&ua.win?"ActiveX":"PlugIn";document.title=document.title.slice(0,47)+" - Flash Player Installation";var dt=document.title;var fv="MMredirectURL="+window.location+"&MMplayerType="+pt+"&MMdoctitle="+dt;var el=obj;if(ua.ie&&ua.win&&obj.readyState!=4){el=document.createElement("div");obj.parentNode.insertBefore(el,obj);obj.style.display="none";window.attachEvent("onload",function(){obj.parentNode.removeChild(obj);});}createSWF({data:_2e.expressInstall,id:"SWFObjectExprInst",width:w,height:h},{flashvars:fv},el);}}function displayAltContent(obj){if(ua.ie&&ua.win&&obj.readyState!=4){var el=document.createElement("div");obj.parentNode.insertBefore(el,obj);el.parentNode.replaceChild(abstractAltContent(obj),el);obj.style.display="none";window.attachEvent("onload",function(){obj.parentNode.removeChild(obj);});}else{obj.parentNode.replaceChild(abstractAltContent(obj),obj);}}function abstractAltContent(obj){var ac=document.createElement("div");if(ua.win&&ua.ie){ac.innerHTML=obj.innerHTML;}else{var _3b=obj.getElementsByTagName("object")[0];if(_3b){var c=_3b.childNodes;if(c){var cl=c.length;for(var i=0;i<cl;i++){if(!(c[i].nodeType==1&&c[i].nodeName.toLowerCase()=="param")&&!(c[i].nodeType==8)){ac.appendChild(c[i].cloneNode(true));}}}}}return ac;}function createSWF(_3f,_40,el){if(ua.ie&&ua.win){var att="";for(var i in _3f){if(typeof _3f[i]=="string"){if(i=="data"){_40.movie=_3f[i];}else{if(i.toLowerCase()=="styleclass"){att+=" class=\""+_3f[i]+"\"";}else{if(i!="classid"){att+=" "+i+"=\""+_3f[i]+"\"";}}}}}var par="";for(var j in _40){if(typeof _40[j]=="string"){par+="<param name=\""+j+"\" value=\""+_40[j]+"\" />";}}el.outerHTML="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\""+att+">"+par+"</object>";fixObjectLeaks();}else{if(ua.webkit&&ua.webkitVersion<312){var e=document.createElement("embed");e.setAttribute("type","application/x-shockwave-flash");for(var k in _3f){if(typeof _3f[k]=="string"){if(k=="data"){e.setAttribute("src",_3f[k]);}else{if(k.toLowerCase()=="styleclass"){e.setAttribute("class",_3f[k]);}else{if(k!="classid"){e.setAttribute(k,_3f[k]);}}}}}for(var l in _40){if(typeof _40[l]=="string"){if(l!="movie"){e.setAttribute(l,_40[l]);}}}el.parentNode.replaceChild(e,el);}else{var o=document.createElement("object");o.setAttribute("type","application/x-shockwave-flash");for(var m in _3f){if(typeof _3f[m]=="string"){if(m.toLowerCase()=="styleclass"){o.setAttribute("class",_3f[m]);}else{if(m!="classid"){o.setAttribute(m,_3f[m]);}}}}for(var n in _40){if(typeof _40[n]=="string"&&n!="movie"){createObjParam(o,n,_40[n]);}}el.parentNode.replaceChild(o,el);}}}function createObjParam(el,_4d,_4e){var p=document.createElement("param");p.setAttribute("name",_4d);p.setAttribute("value",_4e);el.appendChild(p);}function hasPlayerVersion(rv){return (ua.playerVersion[0]>rv[0]||(ua.playerVersion[0]==rv[0]&&ua.playerVersion[1]>rv[1])||(ua.playerVersion[0]==rv[0]&&ua.playerVersion[1]==rv[1]&&ua.playerVersion[2]>=rv[2]))?true:false;}function createCSS(sel,_52){if(ua.ie&&ua.mac){return;}var h=document.getElementsByTagName("head")[0];var s=document.createElement("style");s.setAttribute("type","text/css");s.setAttribute("media","screen");if(!(ua.ie&&ua.win)&&typeof document.createTextNode!="undefined"){s.appendChild(document.createTextNode(sel+" {"+_52+"}"));}h.appendChild(s);if(ua.ie&&ua.win&&typeof document.styleSheets!="undefined"&&document.styleSheets.length>0){var ls=document.styleSheets[document.styleSheets.length-1];if(typeof ls.addRule=="object"){ls.addRule(sel,_52);}}}return {registerObject:function(_56,_57,_58){if(!ua.w3cdom||!_56||!_57){return;}var _59={};_59.id=_56;var v=_57.split(".");_59.swfVersion=[parseInt(v[0],10),parseInt(v[1],10),parseInt(v[2],10)];_59.expressInstall=_58?_58:false;_2[_2.length]=_59;createCSS("#"+_56,"visibility:hidden");},getObjectById:function(_5b){var r=null;if(ua.w3cdom&&_5){var o=document.getElementById(_5b);if(o){var n=o.getElementsByTagName("object")[0];if(!n||(n&&typeof o.SetVariable!="undefined")){r=o;}else{if(typeof n.SetVariable!="undefined"){r=n;}}}}return r;},embedSWF:function(_5f,_60,_61,_62,_63,_64,_65,_66,_67){if(!ua.w3cdom||!_5f||!_60||!_61||!_62||!_63){return;}if(hasPlayerVersion(_63.split("."))){createCSS("#"+_60,"visibility:hidden");var att=(typeof _67=="object")?_67:{};att.data=_5f;att.width=_61;att.height=_62;var par=(typeof _66=="object")?_66:{};if(typeof _65=="object"){for(var i in _65){if(typeof _65[i]=="string"){if(typeof par.flashvars!="undefined"){par.flashvars+="&"+i+"="+_65[i];}else{par.flashvars=i+"="+_65[i];}}}}addDomLoadEvent(function(){createSWF(att,par,document.getElementById(_60));createCSS("#"+_60,"visibility:visible");});}else{if(_64&&!_6&&hasPlayerVersion([6,0,65])&&(ua.win||ua.mac)){createCSS("#"+_60,"visibility:hidden");addDomLoadEvent(function(){var _6b={};_6b.id=_6b.altContentId=_60;_6b.width=_61;_6b.height=_62;_6b.expressInstall=_64;showExpressInstall(_6b);createCSS("#"+_60,"visibility:visible");});}}},getFlashPlayerVersion:function(){return {major:ua.playerVersion[0],minor:ua.playerVersion[1],release:ua.playerVersion[2]};},hasFlashPlayerVersion:function(_6c){return hasPlayerVersion(_6c.split("."));},createSWF:function(_6d,_6e,el){if(ua.w3cdom&&_5){createSWF(_6d,_6e,el);}},createCSS:function(sel,_71){if(ua.w3cdom){createCSS(sel,_71);}},addDomLoadEvent:addDomLoadEvent,addLoadEvent:addLoadEvent,getQueryParamValue:function(_72){var q=document.location.search||document.location.hash;if(_72==null){return q;}if(q){var _74=q.substring(1).split("&");for(var i=0;i<_74.length;i++){if(_74[i].substring(0,_74[i].indexOf("="))==_72){return _74[i].substring((_74[i].indexOf("=")+1));}}}return "";},expressInstallCallback:function(){if(_6&&_4){var obj=document.getElementById("SWFObjectExprInst");if(obj){obj.parentNode.replaceChild(_4,obj);_4=null;_6=false;}}}};}();



var DOMutils = {
	/* http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	},
	/* http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ */
	getElementsByClassName:function(oElm, strTagName, strClassName) {
	    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
	        oElement = arrElements[i];      
	        if(oRegExp.test(oElement.className)){
	            arrReturnElements.push(oElement);
	        }   
	    }
	    return (arrReturnElements)
	}
}
/* http://www.robertnyman.com/2006/10/03/elo-encapsulated-load-object-the-ultimate-way-to-handle-window-load-events/ */
var ELO = {
	loaded : false,
	timer : null,
	functionsToCallOnload : [], // Type in functions as strings here. e.g. "myFunction()"
	init : function (){
		if(ELO.loaded) return;
		ELO.loaded = true;
		ELO.load();
	},
	
	load : function (){
		if(this.timer){
			clearInterval(this.timer);
		}
		for(var i=0; i<this.functionsToCallOnload.length; i++){
			try{
				eval(this.functionsToCallOnload[i]);
			}
			catch(e){
				// Handle error here
			}
		}
	}
};
/*@cc_on @*/
/*@if (@_win32)
	if(document.getElementById){
		document.write("<script id=\"ieScriptLoad\" defer src=\"//:\"><\/script>");
	    document.getElementById("ieScriptLoad").onreadystatechange = function() {
	        if (this.readyState == "complete") {
	            ELO.init();
	        }
	    };
	}
/*@end @*/
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", ELO.init, false);
}
if(navigator.userAgent.search(/WebKit/i) != -1){
    ELO.timer = setInterval(function (){
		if(document.readyState.search(/loaded|complete/i) != -1) {
			ELO.init();
		}
	}, 10);
}
window.onload = ELO.init;


/* http://www.456bereastreet.com/archive/200710/autopopulating_text_input_fields_with_javascript/ */
var autoPopulate = {
	sInputClass:'populate',
	sHiddenClass:'hidden',
	bHideLabels:true,
	init:function() {
		if (!document.getElementById || !document.createTextNode) {return;}
		var arrInputs = DOMutils.getElementsByClassName(document, 'input', autoPopulate.sInputClass);
		var iInputs = arrInputs.length;
		var oInput;
		for (var i=0; i<iInputs; i++) {
			oInput = arrInputs[i];
			if (oInput.type != 'text') { continue; }
			if (autoPopulate.bHideLabels) { autoPopulate.hideLabel(oInput.id); }
			if ((oInput.value == '') && (oInput.title != '')) { oInput.value = oInput.title; }
			DOMutils.addEvent(oInput, 'focus', function() {
				if (this.value == this.title) {
					this.value = '';
					this.select();
				}
			});
			DOMutils.addEvent(oInput, 'blur', function() {
				if (!this.value.length) { this.value = this.title; }
			});
		}
	},
	hideLabel:function(sId) {
		var arrLabels = document.getElementsByTagName('label');
		var iLabels = arrLabels.length;
		var oLabel;
		for (var i=0; i<iLabels; i++) {
			oLabel = arrLabels[i];
			if (oLabel.htmlFor == sId) {
				oLabel.className = oLabel.className + ' ' + autoPopulate.sHiddenClass;
			}
		}
	}
};

ELO.functionsToCallOnload.push("autoPopulate.init()")


function leave_site(myURL)
{
if (! confirm("You will be leaving the PROVENTIL HFA Web site. Click OK to continue, or Cancel to return to ProventilHFA.com.") )
{ return false; }
else
	{
	window.open(myURL);
	return true;
	}
}

  function nav_action(navId) {
    obj = document.getElementById(navId);
    nav_img = document.getElementById("nav_" + navId);
    if (obj.style.display!="none") {
      obj.style.display="none";
      nav_img.src=  imgPath + 'nav_bullet_plus.gif';
	}
    else {
      obj.style.display="block";
      nav_img.src= imgPath + 'nav_bullet_minus.gif';
    }
  }

/* PLUG-IN CHECK */
var requiredVersion = 6;

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var maxVersion = 9;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

jsVersion = 1.1;

if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('<\/SCR' + 'IPT\> \n');
}


function detectFlash() {
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      var flashVersion = parseInt(flashDescription.substring(16));

      flash2Installed = flashVersion == 2;
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }

  for (var i = 2; i <= maxVersion; i++) {
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }

  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 4;

  if (actualVersion >= requiredVersion) {
    hasRightVersion = true;
  }
}

detectFlash();
/* PLUG-IN CHECK END */

function runFlash(swfFile,width,height,id) {
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + '" height="'+ height + '" id="' + id + '" align=""><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + swfFile + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="transparent" /><embed src="' + swfFile + '" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + id +  '" align="" allowScriptAccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');}

function popUp(URL, attributes){
  var popUp = window.open(URL, 'newWindow', attributes)
  popUp.focus();
}


function changeFormAction(theForm, newAction){
  document.forms[theForm].action = newAction;
  document.forms[theForm].submit();
}


function featureTopics(theForm){
  topics = new Array();            //All the topics form elements
  topicsIndex = 0;                 //Topics elements array index
  topicsChkd = new Array();        //Checked topics
  topicsChkdIndex = 0;             //Check topics index

  var hivesChkd = false;
  var qaChkd= false;

  formElements = document.forms[theForm].elements.length;

  for (i=0; i<formElements; i++){
    if(document.forms[theForm].elements[i].name == "topics") {
      topics[topicsIndex] = document.forms[theForm].elements[i];
      topicsIndex++;
    }
  }

  for (i=0; i<topics.length; i++){
    if (topics[i].checked){
      topicsChkd[topicsChkdIndex] = topics[i];
      topicsChkdIndex++;
    }
  }

  if (topicsChkd.length == 1) {
      for (i=0; i<topicsChkd.length; i++){
        if (topicsChkd[i].value == "hives") hivesChkd = true;
        if (topicsChkd[i].value == "q_and_a") qaChkd = true;
      }

      if( hivesChkd || qaChkd){
        for (i=0; i<topics.length; i++){
          if (topics[i].value == "clarinex_inf") topics[i].checked = true;
        }
      }
  }
}

function clearFields(chkbox) {
  if (!chkbox.checked) {
    iElementsToClear = clearFields.arguments.length - 1;
    aElementsToClear = new Array ();

    for (i=0; i<iElementsToClear; i++){
      aElementsToClear[i] = clearFields.arguments[i+1]; // skip first parameter
    }

    for (i=0; i<aElementsToClear.length; i++){
      if (aElementsToClear[i].type == "text") aElementsToClear[i].value = "";
      else if (aElementsToClear[i].type == "radio" || aElementsToClear[i].type == "checkbox") {
        aElementsToClear[i].checked = false;
      }
    }

  }
}


function checkHiddenField(theForm, chkbox, hiddenField){
  if (chkbox.checked) {
      hiddenField.value = true;
  } else {
    hiddenField.value = tempValue;
  }
  theForm.submit();
}

function checkJustHiddenField(theForm, chkbox, hiddenField){
  tempValue = false;
  if (chkbox.checked) {
      hiddenField.value = true;
  } else {
    hiddenField.value = tempValue;
  }
}

function usImgSwap(imgPath){
  document.images.USMAP.src = imgPath;
}

function usThumbnailImgSwap(imgPath){
  document.images.THUMBNAIL.src = imgPath;
}

function openNationalWeatherMap(mapImg){
  var mapWindow = open("", "mapWindow", 'width=660,height=525,resizable');
  mapWindow.focus();
  mapWindow.document.open();
  mapWindow.document.writeln("<html><body><center><img src=" + mapImg + "><br><a href='javascript:window.close()'>Close Window</a></center></body></html>");
  mapWindow.document.close();
}


function linkOffSite(URL){
  if ( confirm("You will be leaving the Proventil&reg; HFA Web site.\nClick OK to continue, or CANCEL to return to ProventilHFA.com") ){
    popUp(URL,'width=640,height=480,location,scrollbars,menubar,toolbar,resizable,directories,status')
  }
}


function validateMonths(theForm, monthGroupNames, yearValue){
  months = new Array();            //All the month form elements
  monthsIndex = 0;                 //Topics elements array index
  monthsChkd = new Array();        //Checked topics
  monthsChkdIndex = 0;             //Check topics index

  formElements = theForm.elements.length;

  // Gather all form elements named monthGroupNames
  for (i=0; i<formElements; i++){
    if(theForm.elements[i].name == monthGroupNames) {
      months[monthsIndex] = theForm.elements[i];
      monthsIndex++;
    }
  }

  // If yearround is checked, uncheck all individual months
  for (i=0; i<months.length; i++){
    if (months[i].value == yearValue && months[i].checked){
      for (j=0; j<months.length; j++) {
        if (months[j].value != yearValue && months[j].checked) {
         months[j].checked = false;
        }
      }
    break;
    }
  }

  theForm.submit();
}



function bCanPrint(){
  if (window.print){
    window.print();
  } else {
    alert('Please select Print under the File menu to print this page.');
  }
}

var date = new Date();
var day  = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

var tmp = date.getHours();
var hour = (tmp <= 12) ? tmp : (tmp-12);
hour = ( hour < 10 ) ? "0" + hour : hour;
var sym = (tmp < 12) ? "am" : "pm";
if (hour == "00"){hr=12;}

var minutes = (( date.getMinutes() < 10) ? "0" : "" ) + date.getMinutes();


/* Refill Reminder date validation */
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date");
		return false;
	}
return true;
}

function isEmpty(str) {
  return (str == null || str == "" || str.length == 0);
}


function pfdDelete(formName) {
  var form = document.forms[formName];
  var itemChecked = 0;

  for (var i=0; i<form.elements.length; i++){
      if (form.elements[i].type == "checkbox" && form.elements[i].name == "delete" && form.elements[i].checked) {
      itemChecked++;
    }
  }

  if (itemChecked) form.submit();
  else alert("Please select an entry to delete.");

}

function closeAndGoto(url) {
  window.close();
  opener.location = url;
  opener.focus();
}

function pfdInfoPop(obj, entryDate, entryTime, reading, score) {
  if (reading > 0){
    obj.firstChild.className="highlight";
    document.onmousemove = getCursor;
    var content = '<div class="detailTitle">' + entryDate + '&nbsp;&nbsp;' + entryTime + '</div><div class="detailBody">Peak Flow Reading: ' + reading + '<br />Symptom Score: ' + score + '</div></div>';
    document.getElementById("barDetailDiv").innerHTML = content;
    setTimeout("document.getElementById('barDetailDiv').style.visibility = 'visible'", 50);
  }
}

function getCursor(e) {
  var x = 0; var y = 0;
  var xOffset = -175; var yOffset = 200;
  if (document.all) {
    x = event.clientX + document.body.scrollLeft;
    y = event.clientY + document.body.scrollTop;
  } else {
    x = e.pageX;
    y = e.pageY;
  }
  document.getElementById("barDetailDiv").style.left = x + xOffset;
  document.getElementById("barDetailDiv").style.top = y + yOffset;
}

function kill(obj){
  document.getElementById("barDetailDiv").style.top = document.getElementById("barDetailDiv").style.left = -1000;
  document.getElementById("barDetailDiv").style.visibility = 'hidden';
  document.onmousemove = '';
  obj.firstChild.className="chartBar";
}

function checkPeakflow() {
  theForm = document.forms['pf.measure.submit'];
  if ( isNaN(theForm.PF_PREDICTED.value) || theForm.PF_PREDICTED.value > 999 ) {
    alert("Please enter a valid predicted peak flow number. (1-999)");
    theForm.PF_PREDICTED.focus();
    theForm.PF_PREDICTED.select();
  }
  else if ( isNaN(theForm.PF_BEST.value) || theForm.PF_BEST.value > 999 ) {
    alert("Please enter a valid personal best peak flow number. (1-999)");
    theForm.PF_BEST.focus();
    theForm.PF_BEST.select();
  }
  else theForm.submit();
}

function disableChoices(action, radioBtns) {
  for (var i=0; i<radioBtns.length; i++) {
      radioBtns[i].disabled = action;
      if (radioBtns[i].disabled) { radioBtns[i].checked = false; }
  }
}

// Checkbox names are passed as extra arguments from function call
function disableCheckboxes(controlCheckbox) {
  if (controlCheckbox.checked) {
    for (var i=1; i<disableCheckboxes.arguments.length; i++) {
      disableCheckboxes.arguments[i].checked = false;
      disableCheckboxes.arguments[i].disabled = true;
    }
  }

  else {
    for (var i=1; i<disableCheckboxes.arguments.length; i++) {
      disableCheckboxes.arguments[i].disabled = false;
    }
  }
}

function setMedicationValues(controlCheckbox) {
  if (controlCheckbox.checked) {
    for (var i=1; i<setMedicationValues.arguments.length; i++){
      setMedicationValues.arguments[i].checked = false;
      setMedicationValues.arguments[i].disabled = true;
    }
  }
}

function setOptinValues(theForm, bbdo_opt_in, optin_direct, optin_email) {
   if (theForm.bbdo_opt_in[1].checked) { disableChoices(true, theForm.bbdo_opt_in_preference) };
   if (bbdo_opt_in)
   {
    return;
   }
   if (optin_direct.indexOf("true")>=0 && optin_email.indexOf("true")>=0)
   {
     theForm.bbdo_opt_in_preference[0].checked=true;
     theForm.bbdo_opt_in[0].checked=true;
     return;
   }
   if (optin_direct.indexOf("false")>=0 && optin_email.indexOf("false")>=0)
   {
     theForm.bbdo_opt_in[1].checked=true;
     return;
   }
   if (optin_direct.indexOf("true")>=0 )
   {

     theForm.bbdo_opt_in_preference[2].checked=true;
     theForm.bbdo_opt_in[0].checked=true;
     return;
   }
   if (optin_email.indexOf("true")>=0 )
   {
     theForm.bbdo_opt_in_preference[1].checked=true;
     theForm.bbdo_opt_in[0].checked=true;
     return;
   }
   if (optin_email.indexOf("false")>=0 )
   {
     theForm.bbdo_opt_in[1].checked=true;
   }
   if (optin_direct.indexOf("false")>=0 )
   {
     theForm.bbdo_opt_in[1].checked=true;
   }
}

function ttProgress(q_answered, q_max) {
  document.getElementById("progressBarFill").style.width = document.getElementById("progressBarTextTop").style.width = (q_answered/q_max) * parseInt(document.getElementById("progressBarContainer").style.width) + 'px';
}

function checkOthers(controlField) {
  for (var i=1; i<checkOthers.arguments.length; i++) {
    if (checkOthers.arguments[i].checked==false) checkOthers.arguments[i].checked=true;
  }
}

function uncheckOthers(controlField) {
  if (controlField.value == "") {
    for (var i=1; i<uncheckOthers.arguments.length; i++) {
      if (uncheckOthers.arguments[i].checked==true) uncheckOthers.arguments[i].checked=false;
    }
  }
}

function clearForm(form) {
	var iFormElements = form.elements.length;
	for (var i=0; i<iFormElements; i++){
		if (form.elements[i].type == "text") form.elements[i].value = "";
	}
}



// Update Profile
  function valForm(theForm){
   optin_selected = document.forms[theForm].bbdo_opt_in[0].checked || document.forms[theForm].bbdo_opt_in[1].checked ;
   optin_pref_selected = document.forms[theForm].bbdo_opt_in_preference[0].checked || document.forms[theForm].bbdo_opt_in_preference[1].checked || document.forms[theForm].bbdo_opt_in_preference[2].checked ;

    if (optin_selected ) {
    	document.forms[theForm].optin_chosen.value="true";
    }

    if (optin_pref_selected ) {
    	document.forms[theForm].optin_chosen.value="true";
    	document.forms[theForm].optin_pref_chosen.value="true";
    	document.forms[theForm].bbdo_opt_in[0].checked = true;
    }

    if ( document.forms[theForm].bbdo_opt_in_preference[0].checked || document.forms[theForm].bbdo_opt_in_preference[2].checked ) {
      var errorList = "";
      if ( document.forms[theForm].street.value == "")       errorList += "  - Street Address\n";
      if ( document.forms[theForm].city.value == "")         errorList += "  - City\n";
      if ( document.forms[theForm].state.selectedIndex == 0) errorList += "  - State\n";

      if (errorList) {
        alert("Please enter the following information:\n\n" + errorList);
        return;
      }
    }

   document.forms[theForm].submit();
  }

// Sign Up
  function getValue(theForm, newAction){
    document.forms[theForm].email_id.value = document.forms[theForm].email.value;
    changeFormAction(theForm, newAction);
  }

function showHideId(aShowIds, aHideIds) {
	for(var i=0; i<aShowIds.length; i++) {
		if (aShowIds[i].indexOf('link') >= 0) document.getElementById(aShowIds[i]).style.display = 'inline';
		else document.getElementById(aShowIds[i]).style.display = 'block';
	}
	for(var i=0; i<aHideIds.length; i++) document.getElementById(aHideIds[i]).style.display = 'none';
}
