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

var _gaq = _gaq || [];

function init() {
	var cookieName = "Canasa";
  	cookieStart = document.cookie.indexOf("cookieName=");

  	if (cookieStart == -1) {
		setTimeout("location.href = '/confirm_us.html'",500);
	}

	if(document.getElementById('healthcare')){
    	cookie2Start = document.cookie.indexOf("cookieName2=");
  		if (cookie2Start == -1) {
			setTimeout("location.href = '/physician_check.html'",500);
		}
	}

    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.URL.match('en/site_map')){
		siteContent = document.getElementById('content4panel');
		siteMapLinks = siteContent.getElementsByTagName('a');
		for(i=0;i<siteMapLinks.length;i++){
			if(siteMapLinks[i].innerHTML == 'The UC Continuum:<BR>Endoscopic Extent of Disease'){
				siteMapLinks[i].innerHTML = 'The UC Continuum: Endoscopic Extent of Disease';
			}
		}
	}

	bgLeft = document.getElementById('container').offsetLeft;
	bgLeft = bgLeft - 20 + 'px';
	document.body.style.backgroundPosition = bgLeft + ' ' + '0px';

	if(document.getElementById('content4panel')){
		newDiv = document.createElement('div');
		newDiv.id = 'thePrintDiv';
		newDiv.style.paddingTop = '10px';
		newDiv.style.textAlign = 'right';
		newDiv.innerHTML = '<form action="/searchresult.php" method="post" style="color:#476b2e;"><a href="index.php" style="color:#476b2e;">Home <img alt="" src="/images/home-icon.gif" style="vertical-align:middle" /></a> &nbsp;&nbsp;&nbsp; Search <input style="vertical-align: middle; width: 125px" name="query" type="text" /><input type="image" alt="" src="/images/search-arrow.gif" style="vertical-align: middle" name="submit" /> &nbsp;&nbsp;&nbsp; <a onclick="printThisPage();" href="#null"><img alt="" src="/images/print-icon.gif" style="vertical-align:middle;" /></a> &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></form>';
		theRight = document.getElementById('content4panel');
		firstRight = theRight.firstChild;
		theRight.insertBefore(newDiv,firstRight);
	}

    if(document.getElementById('patientInfo')){
		newDiv2 = document.createElement('div');
		newDiv2.id = 'loyaltyDiv';
		newDiv.style.width = '534px';
		newDiv2.style.width = '142px';
		newDiv2.style.paddingBottom = '20px';
		newDiv2.style.paddingLeft = '20px';
		newDiv2.style.styleFloat = 'right';
		newDiv2.style.cssFloat = 'right';
		newDiv2.innerHTML = '<a href="http://www.canasacare.com/" target="_blank"><img alt="" src="/images/transparent-button.gif" /></a>';
		firstRight = theRight.firstChild;
		theRight.insertBefore(newDiv2,firstRight);
		theRight.style.background = 'url(/images/loyalty-crest.gif) top right no-repeat';
	}

	if(document.getElementById('topNav')){
		theMainMenu = document.getElementById('topNav');
	}
	
	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;
								theLinkWidth = this.offsetWidth;
								theTop = this.offsetTop;
								theLeft = this.offsetLeft;
								theParent = this.offsetParent;
								while(theParent){
									theTop = theTop + theParent.offsetTop
									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;
		}
	}

	headChild = document.getElementById('header').getElementsByTagName('div')[0];
	headBack = headChild.style.background;

	if(headBack.match('understanding')){
		document.getElementById('topNav').getElementsByTagName('a')[0].style.color = '#b0ce6e';
	}else if(headBack.match('patient-info')){
		document.getElementById('topNav').getElementsByTagName('a')[1].style.color = '#b0ce6e';
    }else if(headBack.match('healthcare')){
		document.getElementById('topNav').getElementsByTagName('a')[2].style.color = '#b0ce6e';
    }else if(headBack.match('contact')){
		document.getElementById('topNav').getElementsByTagName('a')[4].style.color = '#b0ce6e';
    }else if(headBack.match('site-map')){
		document.getElementById('topNav').getElementsByTagName('a')[5].style.color = '#b0ce6e';
	}

    if(document.getElementById('content4panel')){
		fixSize();
	}
}

window.onload=init;

function callGoogle(){
	_gaq.push(['_setAccount', 'UA-23271687-3']);
	_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=Canasa Physician;'

	if(document.referrer != ''){
		history.back();
	}else{
		history.go(-1);
	}
}

function checkTarget2(){
	history.go(-2);
}

function dropMenu(){
	screenWidth = document.body.clientWidth;
	theMenu = document.getElementById(dropMenuId);
	theMenu.style.display = 'block';
	theMenu.style.top = theTop + theHeight + 'px';
	theWidth = theMenu.clientWidth;

	if(theWidth < theLinkWidth){
		theWidth = theLinkWidth;
		theMenu.style.width = theLinkWidth - 4 + 'px';
	}

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
		ieversion=new Number(RegExp.$1);

		if ((ieversion >= 6) && (ieversion < 7)){
			jerrysKids = theMenu.childNodes;

			for(i=0;i<jerrysKids.length;i++){
				if(jerrysKids[i].style){
					jerrysKids[i].style.width = theWidth - 20 + '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 fixSize(){
	document.getElementById('wrapper').style.height = '';

	browserHeight = document.documentElement.clientHeight;
	wrapperHeight = document.getElementById('wrapper').offsetHeight;
	headerHeight = document.getElementById('header').offsetHeight;
	footerHeight = document.getElementById('footer').offsetHeight;

	combinedHeight = wrapperHeight + footerHeight;

	if(combinedHeight < browserHeight){
		document.getElementById('wrapper').style.height = browserHeight - 100 + 'px';
	}
}

function letterSize(f){
	if(f == 2){
		contentDiv = document.getElementById('content4panel');
        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('content4panel').style.font = '14px arial';
		fixSize();
	}
	if(f == 3){
		contentDiv = document.getElementById('content4panel');
        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 = '15px arial';
			}
		}
		document.getElementById('content4panel').style.font = '15px arial';
		fixSize();
	}
	if(f == 1){
		contentDiv = document.getElementById('content4panel');
        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('content4panel').style.font = '12px arial';
		fixSize();
	}
}

function printThisPage() {
	printWin = window.open('http://frsnm2.staging.protected.ca/print.html','','');
}

