//******************************************************************************************************
// Variables used in PageUtility.config for the DART tags
    var axel = Math.random();
    var a = axel * 10000000000000; 


// On load handling      
        
	function page_load()
	{
		callPreloader();
		
		// Declare default font-size
		m_iFontSize_Default = 11;
		m_iFontSize_Max = 13;
		m_iFontSize_Step = 1;	
	   
	}

//******************************************************************************************************


//******************************************************************************************************
// Image handling

	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function MM_showHideLayers() { //v6.0
		var i,p,v,obj,args=MM_showHideLayers.arguments;
		for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v; }
	}

	// Pre-load handling
	var m_sPreloadImgs = "";
	
	function addToPreload(v_sImgPaths)
	{
		(m_sPreloadImgs == "") ? m_sPreloadImgs += v_sImgPaths : m_sPreloadImgs += ", " + v_sImgPaths;
	}

	function callPreloader()
	{
		if (m_sPreloadImgs != "") eval("MM_preloadImages(" + m_sPreloadImgs + ");");
	}
//******************************************************************************************************


//******************************************************************************************************
// Page Tools

	// Bookmark current page
	function BookmarkThisPage()
	{
		var sTitle = "AstraZeneca - " + window.document.title;
		var sUrl = window.document.location.href;
	
		if (window.sidebar)			// Mozilla Firefox Bookmark
			window.sidebar.addPanel(sTitle, sUrl, "");
		else if (window.external)	// IE Favorite
			window.external.AddFavorite(sUrl, sTitle);
		else if (navigator.appVersion.indexOf('Mac') != -1)
			alert('Press Apple+D to bookmark this site.');
		else
			alert('Press Control+D to bookmark this site.');
	}


	// Print current page
	function PrintThisPage()
	{
		if (window.print)
			window.print();
		else
			alert('Select PRINT from the File menu.');
	}

	
	// Share current page - 
	function ShareWithFriend()
	{
		createCookie("page_title", window.document.title, null);
		createCookie("page_address",window.document.location.href, null);
	
		var winShare = window.open("/share-page.aspx", "winShare", "width=400,height=480,toolbar=no,directories=0,status=0,menubar=no,resizable=no,scrollbars=no");
	}
	
	
//*****************************************************************************************************
// Alternate Stylesheet handling

function getPreferredStyleSheet()
{
	var i, a;
	
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
		if((a.getAttribute("rel").indexOf("style") != -1) && (a.getAttribute("rel").indexOf("alt") == -1) && (a.getAttribute("title")))
			return(a.getAttribute("title"));
			
	return(null);
}

function setActiveStyleSheet(title)
{
	var i, a, main;
	
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
		if((a.getAttribute("rel").indexOf("style") != -1) && (a.getAttribute("title")))
			{
			a.disabled = true;
			if(a.getAttribute("title") == title)
				a.disabled = false;
			}
		
	createCookie('FontSize', title);
}
//*****************************************************************************************************






//***********************************************************************************************
// Cookie related functions 

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//***********************************************************************************************


var localLink = false;	
			
		function setupLinks(){
		
			for (var i=0;i<document.links.length;i++){
			if ((document.links[i].href.substring(0, 15) == 'http://localhost') || (document.links[i].href.substring(0,34) == 'http://cdws05.cgdev.com:1000/copd/') || (document.links[i].href.substring(0,41) == 'http://rethinkcopdcontrol.cadientdev.com/') || (document.links[i].href.substring(0,29) == 'http://stage.rethinkcopd.com/') || (document.links[i].href.substring(0,26) == 'http://www.rethinkcopd.com')|| (document.links[i].href.substring(0,22) == 'http://rethinkcopd.com')  )
			document.links[i].onclick = function(){ localLink = true };
			}
			}

//smaller popup with Yes/No options that will lead to the main survey
function launchPreSurvey(){
//			if (!localLink){
//			    	if (readCookie('viewedPreSurvey')==null){
//			        var pageURL = '/survey/presurvey.aspx';
//		            openWindowNoChrome(pageURL,'presurvey',300,200,0,0);	
//			        }	
//			}
}
  
  function setLocal(){
     localLink = true;
  }         
 //Main Key Survey when 'Yes' is clicked
 function launchKeySurvey(vid){
            if (readCookie('viewedPreSurvey')==null){
                createCookie('viewedPreSurvey', 1, 999);            
			//var newwindow = 'http://www.keysurvey.com/survey/244858/2395/';
			    var lLeft =(screen.width - 1000)/2;
				var lTop = (screen.height - 655)/2;	
				openPopUp('http://www.keysurvey.com/survey/260070/127f/?LQID=1&VID=' + vid,'survey','width=1000,height=655,top=' + lTop.toString() + ',left=' + lLeft.toString() + ',scrollbars=yes,align=left,border=0,resizable=no')
				window.close();			
			    winRef.focus();
			}
}

//Close the popup when 'No' is clicked	
function closeWindow() {
createCookie('viewedPreSurvey', 1, 999);
window.close();
}

//******************************************************************************************************
// URLEncode - 

function URLDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function URLEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    str=str.replace(new RegExp('-','g'),'%96');
    return str.replace(new RegExp('%20','g'),'+');
}
//******************************************************************************************************




//******************************************************************************************************
// Expand/contract HTML elements - 

function displaySwitch(r_arrOpen, r_arrClose, v_strDisplayType)
{
	// Open the elements in the first array passed
	for (var i=0; i<r_arrOpen.length; i++)
		if (document.getElementById(r_arrOpen[i]))		
			document.getElementById(r_arrOpen[i]).style.display = (v_strDisplayType == null) ? 'block' : v_strDisplayType;
	
	// Close the elements in second array passed
	for (i=0; i<r_arrClose.length; i++)
		if (document.getElementById(r_arrClose[i]))
			document.getElementById(r_arrClose[i]).style.display = 'none';
}
//******************************************************************************************************


//******************************************************************************************************
// Switch CSS Class

function switchClass(v_sId, sCssClass)
{
	if (document.getElementById(v_sId))
		document.getElementById(v_sId).className = sCssClass;
}
//******************************************************************************************************


//******************************************************************************************************
// Open Window - 

function openWindow(v_sURL, v_sName, v_sFeatures)
{
	winRef = window.open(v_sURL, v_sName, v_sFeatures);

}
//******************************************************************************************************

 //opens specific URL in new popup window
function openWindowNoChrome(pageURL,windowName,pWidth,pHeight,pResize,pScrollbars) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));
  popup=window.open(pageURL,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=0,location=0,directories=0,toolbar=0,scrollbars=' + pScrollbars + ',status=0');
  popup.focus();
}

function openPopUp(v_sURL, v_sName, v_sFeatures)
{
	winRef = window.open(v_sURL, v_sName, v_sFeatures);
}


// Show/Hide Second Date Field for "Between" Option
function showSpan(grup,elemId){
	if (elemId == 1){
		document.getElementById(grup+'EndDate').style.visibility="visible";
	}else{
		document.getElementById(grup+'EndDate').style.visibility="hidden";
	}
}

// EMail this Page
function mailpage()
{
mail_str = "mailto:?subject=Check out " + document.title;
mail_str += "&body=I thought you might be interested in: " + document.title;
mail_str += ". You can view it at, " + location.href; 
location.href = mail_str;
}

// Clear Default Text from Textboxs
	function clearText(thefield){
		if (thefield.defaultValue==thefield.value)
		thefield.value = ""
	} 
	function addText(thefield,thetext){
		if (thefield.value=="")
		thefield.value = thetext;
	}

//******************************************************************************************************
// TEXT ZOOMING

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}


window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
//******************************************************************************************************
// HOVER EFFECTS FOR MENU
sfHover = function() {
	if (document.getElementById("left_nav")) {
	    var sfEls = document.getElementById("left_nav").getElementsByTagName("DIV");
	    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);


// Cookie related functions 
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//survey tool
function launchAsthmaAssessment()
{
	// Save path
	createCookie("SiteSection","1");
	var pageURL = '/copd/survey/start.aspx';
    openWindowNoChrome(pageURL,'survey',790,600,0,1);
}

// Print current page
function PrintThisPage()
{
	if (window.print)
		window.print();
	else
		alert('Select PRINT from the File menu.');
}


//******************************************************************************************************
// POPUP WINDOWS  - 

//variables for centering pop-up windows
var width = screen.width;
var height = screen.height;
var popUpWidth = 0;
var popUpHeight = 0;
var positionTop = 0;
var positionLeft = 0;
var popup = 0;

//popup withOUT browser controls
        //opens current URL in new popup window
function openSameWindowNoChrome(windowName,pWidth,pHeight,pResize,pScrollbars, param,anchor) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));
    
  if (param && param!='')
    sameurl = document.location.href + "&print=true";
  else 
    sameurl = document.location.href + "?print=true";
    
  if (anchor && anchor!='')
    sameurl = sameurl + anchor
    
  popup=window.open(sameurl,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=0,location=0,directories=0,toolbar=0,scrollbars=' + pScrollbars + ',status=0');
	popup.focus();
}
        //opens specific URL in new popup window
function openWindowNoChrome(pageURL,windowName,pWidth,pHeight,pResize,pScrollbars) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));
  popup=window.open(pageURL,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=0,location=0,directories=0,toolbar=0,scrollbars=' + pScrollbars + ',status=0');
  popup.focus();
}

//popup with browser controls
        //opens current URL in new popup window
function openSameWindow(windowName,pWidth,pHeight,pResize,pScrollbars,param,anchor) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));

  if (param && param!='')
    sameurl = document.location.href + "&print=true";
  else 
    sameurl = document.location.href + "?print=true";
       
  if (anchor && anchor!='')
    sameurl = sameurl + anchor
    
  popup=window.open(sameurl, windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=1,location=1,directories=0,toolbar=1,scrollbars=' + pScrollbars + ',status=1');
	popup.focus();
}
        //opens specific URL in new popup window
function openWindow(pageURL,windowName,pWidth,pHeight,pResize,pScrollbars) {
  positionTop = ((height/2) - (pHeight/2));
  positionLeft = ((width/2) - (pWidth/2));
  popup=window.open(pageURL,windowName, config='width=' + pWidth + ',height=' + pHeight + ',left=' + positionLeft + ',top=' + positionTop + ',resizable=' + pResize + ',menubar=1,location=1,directories=0,toolbar=1,scrollbars=' + pScrollbars + ',status=1');
	popup.focus();
}

function disableEnterKey() 
{
	if (window.event.keyCode==13)
	{   
	    return false;
	}	
}

// Dart Tag
function getDartTag(trackUrl) {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    (new Image()).src = trackUrl + ";num=" + a + "?"

}


function GetActionTag(URL){ 
    var TrackTag = 'http://switch.atdmt.com/action/';
  document.action_tag.src = TrackTag + URL;
}
//DOM ready functions
$(function(){
	//navigation rollover function
	$('div.leftNav li').hover(
		function(){
			if ($(this).hasClass('on') == false && $(this).hasClass('sub') == false && $(this).hasClass('espanol') == false){
				$(this).addClass('over');
			}
		},
		function(){
			if ($(this).hasClass('on') == false && $(this).hasClass('sub') == false && $(this).hasClass('espanol') == false){
				$(this).removeClass('over');
			}
		}
	);
	
	//button hovers - buttons and their over state must be named like btnPrintLetterOver.gif and btnPrintLetterOver.gif
	$('input.viewLetter, input.printLetter, input.editName, input.sendLetter').hover(
		function(){
			var currentSrc = ($(this).attr('src')).toString();
			currentSrc = currentSrc.substr(0, currentSrc.length - 4);
			$(this).attr('src', currentSrc + 'Over.gif');
		},
		function(){
			var currentSrc = ($(this).attr('src')).toString();
			currentSrc = currentSrc.substr(0, currentSrc.length - 8);
			$(this).attr('src', currentSrc + '.gif');
		}
	);
	

	 
	 //add onclic for reason callout rotation
	 $("div.next a").bind("click", function(e){
           $("div.rtext").fadeOut("slow",function(){
                     // var extLocation = $("#ReasonSteps").css("background-image").toLowerCase().indexOf(".jpg")
                     //  var i = $("#ReasonSteps").css("background-image").substring(extLocation-1,extLocation);
                    var reasons = [
                        "<span class='reasonSmall'>SYMBICORT helps significantly improve lung function, starting within 5 minutes.*  Remember, Symbicort will not replace a rescue inhaler for sudden symptoms.</span>",
                         "SYMBICORT works all day and all night to help reduce COPD symptoms.",
                        "SYMBICORT helps you breathe more freely.  When you breathe more freely you can get on with your day."]
           
                     var i = $("div.rtext").attr("rel");
           
                     i==3?i=1:i++;

                     $("div.rtext").html(reasons[i-1]);
                     $("div.rtext").attr("rel",i);          
                    $("div.rtext").fadeIn("slow");
                }
           );
    })
	setupLinks();
	 
});



function hideCascade()
{
    hideVideo("imagecontent","flashContent")
}

function showVideo(imageId,videoid)
{
	var videocntr = document.getElementById(videoid);
	if (videocntr)
	{	
		videocntr.style.display = "block";
		videocntr.style.visibility = "visible";
	}
	
	var imagecntr = document.getElementById(imageId);
	if (imagecntr)
	{	
		imagecntr.style.display = "none";
		imagecntr.style.visibility = "hidden";
	}
	
}
function hideVideo(imageId,videoid)
{
	var videocntr = document.getElementById(videoid);
	if (videocntr)
	{	
		videocntr.style.display = "none";
		videocntr.style.visibility = "hidden";
	}
	
	var imagecntr = document.getElementById(imageId);
	if (imagecntr)
	{	
		imagecntr.style.display = "block";
		imagecntr.style.visibility = "visible";
	}
	
}

 
