var theLeft;
var theTop;
var theHeight;
var dropMenuId;

var _gaq = _gaq || [];

function init(){
	var cookieName = "Pylera";
  	cookieStart = document.cookie.indexOf("cookieName=");
  	if (cookieStart == -1) {
    		location.href = "/confirm_us.html";
	}

	if((document.URL.match('/en/healthcare')) || (document.URL.match('/en/product_info')) || (document.URL.match('/en/prescribing')) || (document.URL.match('/en/studies')) || (document.URL.match('/en/pharmacists')) || (document.URL.match('/en/sample_request')) || (document.URL.match('/en/case1')) || (document.URL.match('/en/case2')) || (document.URL.match('/en/case3')) || (document.URL.match('/en/wholesale'))){
		var cookieName2 = "Pylera Physician";
  		cookie2Start = document.cookie.indexOf("cookieName2=");
  		if (cookie2Start == -1) {
			if(document.referrer.match('/es/')){
    				location.href = "/es/physician_check";
			}else{
				location.href = "/en/physician_check";
			}
		}
	}

    ga = document.createElement('script');
	ga.type = 'text/javascript';
	ga.async = true;
    ga.src = 'http://www.google-analytics.com/ga.js';
    document.body.appendChild(ga);

    callGoogle();
	
	if(document.getElementById('mainContent')){
		newDiv = document.createElement('div');
		newDiv.id = 'thePrintDiv';
		newDiv.style.textAlign = 'right';
		newDiv.innerHTML = '<a onclick="printThisPage();" href="#null"><img alt="" src="/images/print-icon.gif" style="vertical-align:middle;" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="letterSize(1)"><img alt="" src="/images/fontsize1.gif" style="vertical-align:middle;" /></a> <a href="#" onclick="letterSize(2)"><img alt="" src="/images/fontsize2.gif" style="vertical-align:middle;" /></a> <a href="#" onclick="letterSize(3)"><img alt="" src="/images/fontsize3.gif" style="vertical-align:middle;" /></a>';
		theRight = document.getElementById('mainContent');
		firstRight = theRight.firstChild;
		theRight.insertBefore(newDiv,firstRight);
	}

	if(document.getElementById('sideBar')){
		if(document.getElementById('sideBar').clientHeight < 594){
			document.getElementById('sideBar').style.height = '564px';
		}
        if(document.getElementById('mainContent').clientHeight < 594){
			document.getElementById('mainContent').style.height = '564px';
		}
	}
	
	var currentPageIs = document.URL;
	var patternToMatch = "/es/";

	if (currentPageIs.match(patternToMatch) == '/es/') {
		document.getElementById('header').style.background = 'url(/images/header-home-sp.jpg)';
	}


	if(document.getElementById('topNav')){
		theMainMenu = document.getElementById('topNav');
	} else {
		theMainMenu = document.getElementById('topNavSpanish');
	}

	mainMenuItems = theMainMenu.childNodes;
	for(i=0;i<mainMenuItems.length;i++){
		if(mainMenuItems[i].className == 'dropItem'){
			mainMenuItems[i].onmouseover = function(){
								dropMenuId = this.innerHTML;
								theHeight = this.offsetHeight;
								theTop = this.offsetTop;
								theParent = this.offsetParent;
								theLeft = this.offsetLeft + 18;
								while(theParent){
									theLeft = theLeft + theParent.offsetLeft;
									theParent = theParent.offsetParent;
								}
								dropMenu();
							}
			mainMenuItems[i].onmouseout = raiseMenu;
		}
	}
	dropMenus = document.getElementById('theDropMenus');
	dropMenuItems = dropMenus.childNodes;
	for(i=0;i<dropMenuItems.length;i++){
		if(dropMenuItems[i].id){
			dropMenuItems[i].onmouseover = function(){
								stay(this.id);
							}
			dropMenuItems[i].onmouseout = raiseMenu;
		}
	}
}

window.onload = init;

function callGoogle(){
	_gaq.push(['_setAccount', 'UA-23271687-13']);
	_gaq.push(['_trackPageview']);
}

function nowLeaving(url){
	document.getElementById('leaving').style.display = 'block';
	document.getElementById('nowLink').href = url;
}

function nowStay(){
	document.getElementById('leaving').style.display = 'none';
}

function setCookie2() {
	document.cookie = 'cookieName2=Pylera Physician; path=/'
	if(document.referrer != ''){
		location.href = document.referrer;
	}else{
		history.go(-1);
	}
}

function checkTarget2(){
	if(window.opener){
		window.close();
	}else if(document.referrer != ''){
		history.go(-1);
	}else{
		history.go(-2);
	}
}

function dropMenu(){
	screenWidth = document.body.clientWidth;
	theMenu = document.getElementById(dropMenuId);
	theMenu.style.display = 'block';
	if(navigator.userAgent.indexOf('AppleWebKit') > -1){
		containerHeight = document.getElementById('container').clientHeight;
		document.body.parentNode.style.height = containerHeight + 'px';
		theMenu.style.top = theTop + theHeight + 'px';
		theWidth = theMenu.clientWidth;
	}else{
		scrolled = document.body.scrollTop;
		theMenu.style.top = theTop + theHeight - scrolled + 'px';
		theWidth = theMenu.clientWidth;
	}

	jerrysKids = theMenu.childNodes;
	for(i=0;i<jerrysKids.length;i++){
		if(jerrysKids[i].style){
			jerrysKids[i].style.width = theWidth - 30 + 'px';
		}
	}

	if((theLeft + theWidth) > screenWidth){
		reduceLeft = (theLeft + theWidth) - screenWidth;
		theMenu.style.left = theLeft - reduceLeft - 2 + 'px';
	}else{
		theMenu.style.left = theLeft + 'px';
	}

}

function stay(thisId) {
	document.getElementById(thisId).style.display = 'block';
}

function raiseMenu(){
	theMenus = document.getElementById('theDropMenus');
	theMenus = theMenus.childNodes;
	for(i=0;i<theMenus.length;i++){
		if(theMenus[i].style){
			if(theMenus[i].style.display == 'block'){
				theMenus[i].style.display = 'none';
			}
		}
	}
}

function letterSize(f){
	if(f == 2){
		contentDiv = document.getElementById('mainContent');
        h1Tags = contentDiv.getElementsByTagName('h1');
		if(h1Tags.length != 0){
			for(i=0;i<h1Tags.length;i++){
				h1Tags[i].style.font = 'bold 20px arial';
			}
		}
        h2Tags = contentDiv.getElementsByTagName('h2');
		if(h2Tags.length != 0){
			for(i=0;i<h2Tags.length;i++){
				h2Tags[i].style.font = '18px arial';
			}
		}
		h3Tags = contentDiv.getElementsByTagName('h3');
		if(h3Tags.length != 0){
			for(i=0;i<h3Tags.length;i++){
				h3Tags[i].style.font = 'bold 16px arial';
			}
		}
		aTags = contentDiv.getElementsByTagName('a');
		if(aTags.length != 0){
			for(i=0;i<aTags.length;i++){
				aTags[i].style.font = '14px arial';
			}
		}
		document.getElementById('mainContent').style.font = '14px arial';
	}
	if(f == 3){
		contentDiv = document.getElementById('mainContent');
        h1Tags = contentDiv.getElementsByTagName('h1');
		if(h1Tags.length != 0){
			for(i=0;i<h1Tags.length;i++){
				h1Tags[i].style.font = 'bold 22px arial';
			}
		}
        h2Tags = contentDiv.getElementsByTagName('h2');
		if(h2Tags.length != 0){
			for(i=0;i<h2Tags.length;i++){
				h2Tags[i].style.font = '20px arial';
			}
		}
		h3Tags = contentDiv.getElementsByTagName('h3');
		if(h3Tags.length != 0){
			for(i=0;i<h3Tags.length;i++){
				h3Tags[i].style.font = 'bold 18px arial';
			}
		}
		aTags = contentDiv.getElementsByTagName('a');
		if(aTags.length != 0){
			for(i=0;i<aTags.length;i++){
				aTags[i].style.font = '16px arial';
			}
		}
		document.getElementById('mainContent').style.font = '16px arial';
	}
	if(f == 1){
		contentDiv = document.getElementById('mainContent');
        h1Tags = contentDiv.getElementsByTagName('h1');
		if(h1Tags.length != 0){
			for(i=0;i<h1Tags.length;i++){
				h1Tags[i].style.font = 'bold 18px arial';
			}
		}
        h2Tags = contentDiv.getElementsByTagName('h2');
		if(h2Tags.length != 0){
			for(i=0;i<h2Tags.length;i++){
				h2Tags[i].style.font = '16px arial';
			}
		}
		h3Tags = contentDiv.getElementsByTagName('h3');
		if(h3Tags.length != 0){
			for(i=0;i<h3Tags.length;i++){
				h3Tags[i].style.font = 'bold 14px arial';
			}
		}
		aTags = contentDiv.getElementsByTagName('a');
		if(aTags.length != 0){
			for(i=0;i<aTags.length;i++){
				aTags[i].style.font = '12px arial';
			}
		}
		document.getElementById('mainContent').style.font = '12px arial';
	}
}

function printThisPage() {
	printWin = window.open('/print.html','','');
}

function newWin(theURL,winName,features) {
        window.open(theURL,winName,features)
}

