/*******************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Variables and functions used throughout website.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// VARIABLES BEGIN
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// VARIABLES END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- creates a new 3/4 browser window for links to other websites throughout site
function openExternalWin(argURL) {
 externalWin = window.open(argURL, null, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500');
 if(externalWin != null) externalWin.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates disclaimer window
function openDisclaimerWin(argURL) {
	var showToolBar = 0;
	if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar=1;
	disclaimerWin = window.open(argURL, null, 'scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=450,height=400,toolbar='+showToolBar);
	if(disclaimerWin != null) disclaimerWin.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a popup window for pdfs
function newPDFWin(argURL) {
 if(!gBrowser.isMac) //if its not a Mac
 {
	popupWinFeatures = "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no";
  window.open(argURL,"",popupWinFeatures);
 }
 else window.open(argURL); //mac fix for OS X
}

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- sets a cookie - jsv 1.0
function setCookie(cookieName, cookieValue, expireDate) { 
 if(expireDate != null)
 {
  //set expiration date for cookie
	var expires = new Date( );                                   
	expires.setTime(expires.getTime( ) + (1000 * 60 * 60 * 24 * expireDate)); //days ahead
 }
 document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/" + ((expireDate == null) ? ";" : "; expires=" + expires.toGMTString());
}

//FUNCTION-- retrieves a cookie - jsv 1.0
function getCookie(cookieName) {
 var cookieNameStr = cookieName + "=";               
 var dc = document.cookie;
	            
 if(dc.length > 0)
 {              
  var beginStr = dc.indexOf(cookieNameStr);       
  if(beginStr != -1) 
  {           
   beginStr += cookieNameStr.length;       
   var endStr = dc.indexOf(";", beginStr);
   if(endStr == -1) {endStr = dc.length;}
   return unescape(dc.substring(beginStr, endStr));
  } 
 }
 return null;
}

//FUNCTION-- deletes a cookie - jsv 1.0
function deleteCookie(cookieName) {
 document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns screen height
function getScreenHeight() {
 return parseInt(screen.height);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns screen width
function getScreenWidth() {
 return parseInt(screen.width);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns height of working area of system's screen, excluding windows taskbar
function getScreenAvailHeight() {
 return parseInt(screen.availHeight);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of working area of system's screen, excluding windows taskbar
function getScreenAvailWidth() {
 return parseInt(screen.availWidth);
}

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of browser window
function getBrowserWindowHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientHeight;
	else return document.body.clientHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasHorizontalScrollbar()) return window.innerHeight-getScrollbarOffSet();
	else return window.innerHeight;
 }
 else return window.innerHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of browser window
function getBrowserWindowWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientWidth;
	else return document.body.clientWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasVerticalScrollbar()) return window.innerWidth-getScrollbarOffSet();
	else return window.innerWidth;
 }
 else if(gBrowser.safari && hasVerticalScrollbar()) //safari
 {
	return window.innerWidth - getScrollbarOffSet();
 }
 else return window.innerWidth;
}

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of body
function getBodyHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollHeight;
	else return document.body.scrollHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasHorizontalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasVerticalScrollbar())	return (window.innerHeight+window.scrollMaxY)-scrollOffSet;
  else return window.innerHeight-scrollOffSet;
 }
 else return document.body.scrollHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of body
function getBodyWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollWidth;
	else return document.body.scrollWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasVerticalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasHorizontalScrollbar())	return (window.innerWidth+window.scrollMaxX)-scrollOffSet;
  else return window.innerWidth-scrollOffSet;
 }
 else return document.body.scrollWidth;
}

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- determines horizontal scrollbar existence
function hasHorizontalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxX > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- determines vertical scrollbar existence
function hasVerticalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxY > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else if(gBrowser.safari) //safari
 {
	if(window.innerWidth == getBodyWidth()) return false;
	else return true;
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- checks if scrollMaxY and scrollMaxX properties are supported
function isScrollMax() {
 if(window.scrollMaxY >= 0 && window.scrollMaxX >= 0) return true;
 else return false;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns vertical scroll position
function getVerticalScrollPosition() {
 if(window.pageYOffset) {return window.pageYOffset;}
 else if(document.documentElement && document.documentElement.scrollTop) {return document.documentElement.scrollTop;}
 else if(document.body) {return document.body.scrollTop;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns horizontal scroll position
function getHorizontalScrollPosition() {
 if(window.pageXOffset) {return window.pageXOffset;}
 else if(document.documentElement && document.documentElement.scrollLeft) {return document.documentElement.scrollLeft;}
 else if(document.body) {return document.body.scrollLeft;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns offset value equal to scrollbar width
function getScrollbarOffSet() {
 if(gBrowser.firefox)
 {
  if(gBrowser.isWin) return 17;
	else if(gBrowser.isMac) return 15;
 }
 else if(gBrowser.safari) {return 15;}
}

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- checks document mode for IE
function checkMode() {
 if(document.all) {return (document.compatMode && document.compatMode != "BackCompat");}
 else {alert("Mode not detected");}
}

//------------------------------------------------------------------------------

//FUNCTION-- sets document mode for IE (documentElement or body based on DOCTYPE used)
function setMode() {
 if(document.all)
 {
	if(checkMode()) {DOCUMENTMODE = document.documentElement;}
	else {DOCUMENTMODE = document.body;}
 }
 else {alert("Unable to set mode");}
}

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns left coordinates for object centering
function getObjectPositionLeft(argScreenWidth, argObjWidth) {
 if(argObjWidth < argScreenWidth)
 {
  var halfScreenWidth = parseInt(argScreenWidth/2);
  var halfObjWidth = parseInt(argObjWidth/2); 
  return ((halfScreenWidth-halfObjWidth)+getHorizontalScrollPosition());
 }
 else return 0;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns top coordinates for object centering
function getObjectPositionTop(argScreenHeight, argObjHeight) {
 if(argObjHeight < argScreenHeight)
 {	
  var halfScreenHeight = parseInt(argScreenHeight/2);
  var halfObjHeight = parseInt(argObjHeight/2); 
  return ((halfScreenHeight-halfObjHeight)+getVerticalScrollPosition());
 }
 else return getVerticalScrollPosition();
}	

//------------------------------------------------------------------------------

//FUNCTION-- validate top position
function isValidatePositionTop(argTopPosition, argObjectHeight, argBrowserWindowHeight) {
 if(argTopPosition <= 0 || (argTopPosition+argObjectHeight) > argBrowserWindowHeight) return false;
 else return true;
}

//------------------------------------------------------------------------------

//FUNCTION-- validate left position
function isValidatePositionLeft(argLeftPosition, argObjectWidth, argBrowserWindowWidth) {
 if(argLeftPosition <= 0 || (argLeftPosition+argObjectWidth) > argBrowserWindowWidth) return false;
 else return true;
}

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG BEGIN
//------------------------------------------------------------------------------

leavingDialog = new Spawn_Object("leavingSiteDiv");
leavingBayer = new Spawn_Object("leavingBayerDiv");

//FUNCTION-- init dailogs
function initDialogs() {
 var grayMask = initMask("mask01", "/images/mask_grayAlpha.png"); //initialize mask

 leavingDialog.m_initDialogProperties(grayMask, "siteExit"); //init common dialog properties [mask=mask object or null | dialogType=string]
 leavingBayer.m_initDialogProperties(grayMask, "siteExit"); //init common dialog properties [mask=mask object or null | dialogType=string]

 activeDialog = null;
 activeStackDialog = null;
 window.onresize = adjustDialog;
}

addOnLoadEvent(initDialogs);

//------------------------------------------------------------------------------
// DIALOG END
//------------------------------------------------------------------------------



//------------------------------------------------------------------------------
// Signup Validation
//------------------------------------------------------------------------------
function formValidate(validloc){
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var hasError = false;
	
	var formval = document.getElementById('email').value;
	if(formval == '') {
		var errorMsg = 'Please enter an email address';
		hasError = true;
	} else if (!emailReg.test(formval)) {
		var errorMsg = 'Please enter a valid email address';
		hasError = true;
	}
	
	if (hasError){
		alert(errorMsg);
	} else {
		window.location="validloc";
	}
}


//missed pills code

var flashmarkup = '<div id="flashwrap">';
flashmarkup += '<div id="flashwrap_top">&nbsp;</div><div id="flashwrap_headerisi">';
//flashmarkup += '<h3><span>Important Safety Information About Natazia</span> <a href="http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf" target="_blank">Prescribing Information</a></h3><a href="#" id="flashwrap_close">CLOSE X</a><p>Do not use Natazia if you smoke cigarettes and are over 35 years old. Smoking increases your risk of serious cardiovascular side effects (heart and blood vessel problems) from birth control pills, including death from heart attack, blood clots or stroke. This risk increases with age and the number of cigarettes you smoke. <a href="#flashisi" class="anchor">continue reading below</a></p></div>';
flashmarkup += '<a href="#" id="flashwrap_close">X</a><a href="index.html"><img id="nLogo" src="images/natazia_logo_sm.gif" alt="Natazia(R)" width="241" height="59" border="0" /></a><div id="hdISI"><h3>Important Safety Information About Natazia<br /><a href="http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf" target="_blank">Prescribing Information, including Boxed WARNING</a></h3><p>WARNING TO WOMEN WHO SMOKE: Do not use Natazia if you smoke cigarettes and are over 35 years old. Smoking increases your risk of serious cardiovascular side effects (heart and blood vessel problems) from birth control pills, including death from heart attack, blood clots or stroke. This risk increases with age and the number of cigarettes you smoke. <a href="#flashisi" class="anchor">See additional important risk information below</a></p></div><a href="http://pharma.bayer.com/scripts/pages/en/index.php" id="bayer" target="_blank" onclick="openExternalWin(this.href); return false;"><img id="bLogo" src="images/bayer_logo.gif" width="67" height="67" border="0" alt="Bayer logo"/></a><br clear="all" /></div>';


flashmarkup += '<div id="flashwrap_header"><div id="flashwrap_header_nav"><a href="#" id="mpt"></a><a href="#" id="isi"></a><a href="http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf" target="_blank" id="pi"></a></div></div>';
flashmarkup += '<div id="flashwrap_content"><div id="flashcontent"><h1>Select the Pills You\'ve Missed</h1><p class="noflash"><span>Get Adobe<sup>&trade;</sup> Flash<sup>&trade;</sup> Player</span><br><br>The NATAZIA (estradiol valerate and dienogest) Missed Pill Tool requires Adobe<sup>&trade;</sup> Flash Player software. You can download Flash Player from the <a href="http://get.adobe.com/flashplayer/" onclick="leavingDialog.m_setResource(this); return false;">Adobe Flash Player download page</a>.<br><br><br><br><br><br><br></p><h2>Important</h2><ul><li>The right way to take birth control pills is to take one pill every day at the same time, and in the order as directed on the blister pack</li><li>If you miss pills, you could get pregnant. This includes starting the pack late</li><li>The more pills you miss, the more likely you are to get pregnant</li><li>Missing pills can also cause spotting or light bleeding, even when you take the missed pills later</li><li>No more than TWO PILLS should be taken in any single day</li><li>On the days you take two pills to make up for missed pills, you could also feel a little sick to your stomach</li></ul><p><strong>You may already be pregnant or COULD BECOME PREGNANT if you had sex in the days after the pills were missed. The more pills missed and the closer they are to the end of the cycle, the higher the risk of a pregnancy. You should call your doctor or healthcare provider if you are unsure whether you are already pregnant.</strong></p><p><strong>You may not have your period this month, but this is not uncommon. However, if you miss your period two months in a row, you should call your doctor or healthcare provider because you might be pregnant.</strong></p><p><strong>For more information, refer to the What should I do if I miss any Pills section of the Prescribing Information. FINALLY, IF YOU ARE STILL NOT SURE OF WHAT TO DO ABOUT THE PILLS YOU HAVE MISSED:</strong></p><ul><li><strong>CONTACT YOUR HEALTHCARE PROVIDER</strong></li><li><strong>USE BACKUP CONTRACEPTION (such as condoms or spermicides) anytime you have sex and KEEP TAKING ONE PILL EACH DAY</strong></li></ul></div>';

flashmarkup += '<p id="flashisi"><strong>What is NATAZIA<sup>&reg;</sup> prescribed for?</strong> Natazia is a birth control pill approved to prevent pregnancy. Natazia can also be used for the treatment of heavy menstrual bleeding that is not caused by any diagnosed conditions of the uterus in women who decide to use oral contraception.</p><p>NATAZIA has not been studied in women who are obese (BMI &gt;30).</p><p><strong>Who Should Not Take Natazia?</strong></p><p class="box"><strong>Do not use Natazia if you smoke and are over age 35. Smoking increases your risk of serious side effects from the Pill, which can be life-threatening, including blood clots, stroke or heart attack. This risk increases with age and the number of cigarettes smoked.</strong></p><p>Do not use Natazia if you have or have had blood clots, certain cancers, history of heart attack or stroke, or if you are or may be pregnant.</p><p><strong>What are the most serious risks of taking Natazia?</strong><br />Natazia increases the risk of serious conditions including blood clots, stroke, and heart attack. The risk of blood clots is highest during the first year of use.</p><p><strong><em>Natazia does not protect against HIV infection (AIDS) or other STDs.</em></strong></p><p><strong>What are the most common side effects?</strong><br />In clinical trials, the most common side effects were headache/migraines, irregular periods, breast pain/tenderness, acne, mood changes, weight gain, and nausea/vomiting.</p><p><strong>Tell your healthcare provider</strong> about all medicines and herbal products you take including daily long-term treatment for chronic conditions such as seizures or cardiovascular disease.</p><p><strong>You are encouraged to report negative side effects of prescription drugs to the FDA. Visit <a href="http://www.fda.gov/medwatch" target="_blank" onclick="leavingDialog.m_setResource(this); return false;">www.fda.gov/medwatch</a>, or call 1-800-FDA-1088.</strong></p><p>Please see <a href="http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf" target="_blank">full Prescribing Information</a> about Natazia, including boxed warning.</p><p>Bayer<sup>&reg;</sup>, the Bayer Cross<sup>&reg;</sup>, and Natazia<sup>&reg;</sup> are trademarks of Bayer. All other trademarks are the property of their respective owners.</p>';

flashmarkup += '</div><div id="flashwrap_footer"></div></div>';

$(document).ready(function(){
	$('.flashact').click(function(){
		dcsMultiTrack('DCS.dcssip', 'www.natazia.com','DCS.dcsuri', '/scripts/pages/MissedMyPillTool.html', 'WT.ti', 'Missed%20My%20Pill%20Tool');

		$('body').append('<div id="flashmask"></div>');
		
		qi_resizemask();
		
		$('#flashmask').css({opacity: .8});
		$('body').append(flashmarkup);
		
		$('#flashcontent, #flashwrap').css({width: '100%'});
		var so = new SWFObject("NataziaMissedPill.swf", "Qlaira Missed Pill", "764", "900", "8", "#FFFFFF");
		so.addParam("wmode", "transparent");
		so.addVariable("pi_link", "http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf");
		so.write("flashcontent");
		
		qi_resizemask();
		
		$('#flashwrap_header_nav a:not(#pi)').click(function(){
			$(this).parent().removeClass();
			var tempclass = 'h_' + $(this).attr('id');
			$(this).parent().addClass(tempclass);
			
			switch ($(this).attr('id')){
				case 'mpt' :
					$('#flashcontent').height(900);
					$('#flashwrap_content').css({'padding-top': 0});
					break;
				case 'isi' :
					$('#flashcontent').height(0);
					$('#flashwrap_content').css({'padding-top': 10});
					break;
			}
			
			$(this).blur();
			return false;
		}).attr('href', '');
		
		$('#flashwrap_close').click(function(){
			$('#flashmask, #flashwrap').animate({opacity: 0}, 200, function(){
				$('#flashmask, #flashwrap').remove();
			});
			return false;
		});
		
		removeAnchorHash();
		
		$(window).resize(function(){
			qi_resizemask();
		});
		
		$(this).blur();
		return false;
	});
	
	function qi_resizemask(){
		$('#flashmask, #flashwrap').height(1);
		
		var h = Math.max($(window).height(), $('body').height(), $(document).height(), $('#wrapper').outerHeight());
		$('#wrapper, #flashmask, #flashwrap').height(h);
	}
	
	removeAnchorHash();
});



function removeAnchorHash(){
	if ($.browser.msie){
		/*
		$('a.anchor').unbind('click').click(function(){
			var tempurl = $(this).attr('href');
			tempurl = tempurl.substring(tempurl.lastIndexOf('#') + 1, tempurl.length);
			$(window).scrollTop($('a[name="' + tempurl + '"]').offset().top);
			
			return false;
		});
		*/
	};
}


function flashExternalInterfaceReceiver(argValue){
	switch(argValue){
    case "NataziaPDF":
			newPDFWin('http://berlex.bayerhealthcare.com/html/products/pi/natazia_pi.pdf');			
      break;
		case "top":
			var wt = Math.floor($(window).scrollTop());
			var wh = Math.floor($(window).height());
			var ft = Math.floor($('#flashcontent').offset().top);
			var fh = Math.floor($('#flashcontent').height());
			
			if (!(wt < ft && ft + fh < wt + wh)){
				$(window).scrollTop(5)
			}
			
			break;
    default:
      alert("flashExternalInterfaceReceiver: NO MATCHES FOUND" + argValue);
  }
}

actionTagArr = new Array(); //create array to hold image objects
//FUNCTION-- tags action
function tagAction(argSrc) {
 var dateObj = Date().replace(/\:/g, ""); //create date and remove colons
 dateObj = dateObj.replace(/\s/g, ""); //remove white space from date
 var imageObj = new Image(); //create image object
 imageObj.src = argSrc + "&date=" + dateObj; //append time stamp to image src as parameter to avoid image caching
 actionTagArr.push(imageObj); //store the image object in an array
}
