

function showHideArtsInSection(eleID) {
  var thisEle = null;
	if (thisEle = document.getElementById('othArtAllDiv_' + eleID)) {
		if (thisEle.style.visibility != 'visible') {
			var height = thisEle.offsetHeight;
			thisEle.style.top = ((45-height) + document.getElementById('othArtDiv_' + eleID).offsetHeight) + 'px';
			thisEle.style.visibility = 'visible';
		} else{
			thisEle.style.visibility = 'hidden';
		}

	}
}


/***************** START top login/register pabel functions *******************/

var visibleAccountPanelID = null;

function showAccountPanel(which) {

    if (visibleAccountPanelID) {
        hideAccountPanel();    
    }

    visibleAccountPanelID = which;

    document.getElementById(visibleAccountPanelID + 'Div').style.display = 'block';
    document.getElementById(visibleAccountPanelID + 'TabTop').style.display = 'block';

}

function hideAccountPanel() {

    if (visibleAccountPanelID != null && visibleAccountPanelID != '') {

        document.getElementById(visibleAccountPanelID + 'Div').style.display = 'none';
        document.getElementById(visibleAccountPanelID + 'TabTop').style.display = 'none';

        if (visibleAccountPanelID == 'loginRegister') {
            unHilightLoginRegister('login');
            unHilightLoginRegister('register');
            document.getElementById('loginRegisterSides').style.display = 'block';
            document.getElementById('forgotPassword').style.display = 'none';
        } else if (visibleAccountPanelID == 'account') {
            if (top.frames.profileIframe.collapseDiv) {
                top.frames.profileIframe.collapseDiv();
            }
        }
    }

    hideAccountActionMsgDiv();
    visibleAccountPanelID = null;
}

function hilightLoginRegister(which) {
    if (which == 'login') {
        unHilightLoginRegister('register');
        if (document.getElementById(which + 'Side')) {
           document.getElementById(which + 'Side').style.backgroundColor='#dfdfdf';
        }

    } else {
        unHilightLoginRegister('login');
        if (document.getElementById(which + 'Side')) {
           document.getElementById(which + 'Side').style.backgroundColor='#dfdfdf';
        }
    }

}

function unHilightLoginRegister(which) {
     if (document.getElementById(which + 'Side')) {
        document.getElementById(which + 'Side').style.backgroundColor='transparent';
     }

}

function showForgotPassword() {
    //this is only called when loginRegisterDiv is the visible panel
    document.getElementById('loginRegisterSides').style.display = 'none';
    document.getElementById('forgotPassword').style.display = 'block';
}


function doLogin() {
    var f = document.loginForm;
    if (!validateEmail(f.Accountowner_Username.value, 'Your', 'loginForm.Accountowner_Username')) {
        return(void(0));
    }

    if (f.Accountowner_Password.value == '') {
        alert('Please enter your password.');
        f.Accountowner_Password.focus();
        return(void(0));
    }

    f.submit();

}

function doRegister() {

    var f = document.registerForm;

    if (f.Accountowner_Pseudonym.value == '') {
        alert('Please enter a name for this account. This name does not have to be your real name.');
        f.Accountowner_Pseudonym.focus();
        return(void(0));
    }

    if (!validateEmail(f.Accountowner_Username.value, 'Your', 'registerForm.Accountowner_Username')) {
        return(void(0));
    }

    if (f.Accountowner_UsernameConfirm.value != f.Accountowner_Username.value) {
        alert('Your confirmation email does not match the email you entered.');
        f.Accountowner_UsernameConfirm.focus();
        return(void(0));
    }

    if (f.Accountowner_Password.value == '' || f.Accountowner_Password.value.length < 6) {
        alert('Please enter a password for your account of at least 6 characters.');
        f.Accountowner_Password.focus();
        return(void(0));
    }

    if (f.Accountowner_Password.value != f.Accountowner_PasswordConfirm.value) {
        alert('Your confirmation password does not match the password you entered.');
        f.Accountowner_PasswordConfirm.focus();
        return(void(0));
    }

    f.submit();

}


function doPasswordReset() {
    var f = document.passwordForm;

    if (!validateEmail(f.Accountowner_Username.value, 'Your', 'passwordForm.Accountowner_Username')) {
        return(void(0));
    }

    f.submit();

}

var visibleSubPanelID = 'profile';

function showAccountSubPanel(which) {
    if (visibleSubPanelID) {
        hideAccountSubPanel();
    }

    visibleSubPanelID = which;

    document.getElementById(visibleSubPanelID + 'Div').style.display = 'block';
    document.getElementById(visibleSubPanelID + 'Head').className = 'headerOn';
}


function hideAccountSubPanel() {

    if (visibleSubPanelID != null && visibleSubPanelID != '') {
        document.getElementById(visibleSubPanelID + 'Div').style.display = 'none';        
        document.getElementById(visibleSubPanelID + 'Head').className = 'headerOff';
        visibleSubPanelID = null;
    }

    hideAccountActionMsgDiv();
}

function checkForJustLoggedInOrRegistered() {
    //is we just logged in, show the login success message
    //and remove the cookie
    //alert($.cookie('justLoggedIn'));
    //alert($.cookie('justRegistered'));
    if ($.cookie('justLoggedIn')) {
        $.cookie('justLoggedIn', null, {path: '/'});
        showJustLoggedIn();
    }

    if ($.cookie('justRegistered')) {
        $.cookie('justRegistered', null, {path: '/'});
        showJustRegistered();
    }
}

function showJustLoggedIn() {
    showAccountSubPanel('profile');
    showAccountPanel('account');
}

function showJustRegistered() {
    showAccountSubPanel('profile');
    showAccountPanel('account');
    top.showAccountActionMsgDiv('Welcome to DNA Direct.<br>Your registration was successful.', 'note');
}

function showAccountActionMsgDiv(message, type) {

    if (type == 'error') {
        document.getElementById('accountActionSymbol').innerHTML = '!';
        document.getElementById('accountActionMsgDiv').style.borderColor = '#6B1515';
        document.getElementById('accountActionMsgDiv').style.color = '#6B1515';
    } else if (type == 'note') {
        document.getElementById('accountActionSymbol').innerHTML = '<span style="position:relative;top:15px;">*</span>';
        document.getElementById('accountActionMsgDiv').style.borderColor = '#247B13';
        document.getElementById('accountActionMsgDiv').style.color = '#247B13';
    }

    document.getElementById('accountActionMsg').innerHTML = message;
    document.getElementById('accountActionMsgDiv').style.display = 'block';
}

function hideAccountActionMsgDiv() {
    document.getElementById('accountActionMsg').innerHTML = '';
    document.getElementById('accountActionMsgDiv').style.display = 'none';
}

function resizeAccountIframe(which, height, width) {
    if (height) {
        document.getElementById(which + '_iframe').style.height = height + 'px';
    }

    if (width) {
        document.getElementById(which + '_iframe').style.width = width + 'px'; 
    }
}


/***************** END top login/register pabel functions *******************/

/***************** REPORT funcs *********************************************/

var reportWindow = null;
function popReport(reportURL) {

	var theParms = 'resizable=1,scrollbars=1,width=740';

	if (screen.height && (screen.height > 0)) {
		theParms += ',height=' + (screen.height - 75);
	}

	reportWindow = window.open(reportURL, 'repWin', theParms);

}

/*****************END REPORT funcs ******************************************/
if (typeof(dna) === "undefined")
  var dna = {};

dna.utils = {

  extractAnchor : function(url)
  {
    var anchorReg = /#(.*)$/g, matches = []
    matches = url.match(anchorReg);
    if (matches !== null)
      return matches[0].substr(1, matches[0].length)
    else
      return null
  },

  createStyleLink : function(stylesheetPath, media, documentContext)
  {
    var link = documentContext.createElement('link');
    link.setAttribute('rel', 'stylesheet');
    link.setAttribute('type', 'text/css');
    link.setAttribute('href', stylesheetPath);
    link.setAttribute('media', media);
    return link;
  }

}

dna.utils.textSize = {

  COOKIE_NAME : "text_size",
  SIZE_SELECTOR : "#textSize a",
  BASE_ELEMENT_SELECTOR : "body>div",

  sizes : {
    "normal" : "100.01%" ,
    "medium" : "125%",
    "large" : "150%"
  },

  cookieProperties : {
    // see jquery.cookie.js for valid properties
    path : "/"
  },

  sizesToString : function()
  {
    var classString = '';
    for (var key in this.sizes)
      classString += ' ' + key;
    return classString;
  },


  setSize : function(size)
  {
    if (this.sizes[size] === 'undefined')
      return this;
    $.cookie(this.COOKIE_NAME, size, this.cookieProperties);
    return this;
  },

  getSize : function()
  {
    return $.cookie(this.COOKIE_NAME);
  },

  activate : function()
  {
    if (this.getSize() === null)
      return this;
    $(this.BASE_ELEMENT_SELECTOR)
        .removeClass(this.sizesToString())
        .addClass(this.getSize());
    return this;
  }
}


function capName(theName) {
	var cappedName = '';

	cappedName = theName.substring(0, 1).toUpperCase() + theName.substring(1, theName.length).toLowerCase();

	return(cappedName);
}


function replace(string,text,by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function getSecondsParm() {
	var thisTime = new Date();
	return(thisTime.getTime());
}


/************** FADERS *************************/

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;

	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

var fading = false;

function fadeIn(objId,opacity, interval, increment, showWhenStarting) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (showWhenStarting) {
			obj.style.visibility = 'visible';
		}
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += increment;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+"," + interval + ", " + increment + ")", interval);
		} else {
			setOpacity(obj, 100);
		}
	}
}

function fadeOut(objId,opacity,interval, increment, hideWhenFinished) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity -= increment;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+"," + interval + ", " + increment + ", " + hideWhenFinished + ")", interval);
		} else {
			setOpacity(obj, 0);
			if (hideWhenFinished) {
				obj.style.visibility = 'hidden';
			}
		}
	}
}

function animateMove(objID, finalPos, interval, increment, whichWay) {

    if (document.getElementById) {
        obj = document.getElementById(objID);
        objDim = (replace(eval('obj.style.' + whichWay), 'px', '')-0);
        var operator = '>=';
        if (increment > 0) {
            operator = '<=';
        }

        if (eval(objDim + ' ' + operator + ' ' + finalPos)) {
            if (objDim != finalPos) {
                objDim += increment;
                eval('obj.style.' + whichWay + ' = ' + objDim + ' + \'px\';');
                setTimeout('animateMove(\'' + objID + '\',' + finalPos + ',' + interval + ',' + increment + ', \'' + whichWay + '\')', interval);
            }
        }

    }

}


function rnd() {
    var today = new Date();
    this.seed = today.getTime();
    this.seed = (this.seed * 9301 + 49297) % 233280;
    return this.seed / (233280.0);
}

 function rand(number) {
    return Math.ceil(rnd() * number);
}
//set global anv vars

var isSafari = navigator.userAgent.toLowerCase().indexOf('safari')!=-1;
var isNetscape = navigator.userAgent.toLowerCase().indexOf('netscape')!=-1;
var isIE = navigator.userAgent.toLowerCase().indexOf('msie')!=-1;

var whichVideo = '';


function Trim(TRIM_VALUE) {
  TRIM_VALUE.replace(/^\s+|\s+$/g,'');
}

function findPos(obj) {

	obj = document.getElementById(obj.id);

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}

	return [curleft,curtop];
}


function replace(string,text,by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function getSecondsParm() {
	var thisTime = new Date();
	return(thisTime.getTime());
}

function exists(thing) {

	if (thing != null) {
		if ((thing + '') == '0') {
			return(true);
		} else if (thing) {
			return(true);
		}
	}

	return(false);
}


function formatDollars(decimalDollars) {

	var formattedDollars = decimalDollars + '';

	if (formattedDollars.indexOf('.')== -1) {
		formattedDollars += '.00';
	} else if (formattedDollars.indexOf('.') == formattedDollars.length-2) {
		formattedDollars += '0';
	}

	formattedDollars = '$' + formattedDollars;

	return(formattedDollars);

}



//button writers for legacy tools

function getOrangeButtonML(btnText, theOnClick, flote, width, btnTxtID) {
	return makeButton(btnText, theOnClick, btnTxtID);
}

function getBigOrangeButtonML(btnText, theOnClick, flote, width, btnTxtID) {
	return makeButton(btnText, theOnClick, btnTxtID);
}

function getBlueButtonML(btnText, theOnClick, flote, width, btnTxtID) {
	return makeButton(btnText, theOnClick, btnTxtID);
}

function makeButton(btnText, theOnClick, btnTxtID, cssClass) {
  return '<a class="button' + (exists(cssClass)?' '+cssClass:'') + '" href="javascript:void(0)" id="' + (exists(btnTxtID)?btnTxtID:'') + '" onClick="' + theOnClick + '">' + btnText  + '</a>';
}


var thisImagePop = null;
var thisCurrImage = null;

function popPic(thisURL, caption) {

	var imgURL = thisURL;

	thisCurrImage = new Image;
	thisCurrImage.src= imgURL;

	if (!exists(caption)) {
		thisImagePop = window.open(imgURL, 'pic', 'title=0,resizable=1,scrollbars=0,status=0,width=300,height=300');
		watchResize();
	} else {
		var thisImagePageML = '<html><head>' +
								'<link REL="shortcut icon" HREF="/siteIcon.ico">' +
								'<script type="text/javascript" src="/js/siteFunctions.js"></script>' +
								'<link rel="stylesheet" type="text/css" href="/css/site.css" media="screen">' +
								'</head>' +
								'<body style="margin-top:5px;" onLoad="watchResize(\'contDiv\')">' +
								'<div id="contDiv" style="text-align:left;margon-left:auto;margin-right:auto;">' +
								'<img src="' + imgURL + '" id="img1"><br>' +
								'<img src="/img/blank.gif" height="5"><br>' +
								caption +
								'</div>' +
								'</body></html>';

		thisImagePop = window.open(imgURL, 'pic', 'title=0,resizable=1,scrollbars=0,status=0,width=300,height=300');
		thisImagePop.document.write(thisImagePageML);
		thisImagePop.document.close();

	}


	thisImagePop.focus();
}

function watchResize(divName) {

	if (exists(divName)) {
		if (opener.thisCurrImage.height > 0) {
			window.resizeTo(opener.thisCurrImage.width + 50, document.getElementById(divName).offsetHeight + 80);

		} else {
			setTimeout('watchResize(\'' + divName + '\')', 100);
		}


	} else {
		if (thisCurrImage.height > 0) {
			thisImagePop.resizeTo(thisCurrImage.width + 50, thisCurrImage.height + 80);
		} else {
			setTimeout('watchResize()', 100);
		}
	}

}

var poppedWin = null;

function popWin(theURL, theWidth, theHeight) {

	var width = 200;
	var height = 200;

	if (exists(theWidth)) {
		width = theWidth - 0;
	}

	if (exists(theHeight)) {
		height = theHeight - 0;
	}

	poppedWin = window.open(theURL, 'PoppedWindow', 'title=0,resizable=1,scrollbars=1,status=0,width=' + width + ',height=' + height);

}


var validEmailChars = 'abcdefghijklmnopqrstuvwxyz1234567890@._-+';

function validateEmail(theEmail, emailTitle, emailObjectName) {

   if (Trim(theEmail) == '') {
      alert('Please enter an email address.');
	  if (exists(emailObjectName)) {
			if (eval('document.' + emailObjectName)) {
				eval('document.' + emailObjectName + '.focus();');
			}
		}
      return(false);
   }

   theEmail = theEmail.toLowerCase();

   if (theEmail != null) {

      for (i=0; i<theEmail.length; i++) {
       if (validEmailChars.indexOf(theEmail.charAt(i)) == -1) {
          alert((exists(emailTitle)?emailTitle:'This') + ' email address contains a \'' + theEmail.charAt(i) + '\' character which is invalid. Please re-enter this email address.');
		if (exists(emailObjectName)) {
			if (eval('document.' + emailObjectName)) {
				eval('document.' + emailObjectName + '.focus();');
			}
		}
          return(false);
       }

      }
   }
   if (theEmail.indexOf('@') == -1) {
       alert((exists(emailTitle)?emailTitle:'This') + ' email address lacks an \'@\' character. Please re-enter this email address.');
		if (exists(emailObjectName)) {
			if (eval('document.' + emailObjectName)) {
				eval('document.' + emailObjectName + '.focus();');
			}
		}
       return(false);
   } else if ((theEmail.indexOf('@') == theEmail.length-1) || (theEmail.length < 6) || (theEmail.indexOf('@') == 0)) {
       alert((exists(emailTitle)?emailTitle:'This') + ' email address appears to be incomplete. Please re-enter this email address.');
		if (exists(emailObjectName)) {
			if (eval('document.' + emailObjectName)) {
				eval('document.' + emailObjectName + '.focus();');
			}
		}
       return(false);
   } else if (theEmail.indexOf('.') == -1) {
		alert((exists(emailTitle) ? emailTitle : 'This') + ' email address lacks a domain extension such as \'.com\' or \'.net\'. Please re-enter this email address.');
		if (exists(emailObjectName)) {
			if (eval('document.' + emailObjectName)) {
				eval('document.' + emailObjectName + '.focus();');
			}
		}
		return(false);
	}

   return(true);
}

$(function(){

  var textSize = dna.utils.textSize;
  textSize.activate();

  // register change text size event handlers
  $(textSize.SIZE_SELECTOR).click(function(event) {
    var size = $(event.target)[0].className;
    textSize.setSize(size).activate();
  })

})

function getCPTCodesWindow(testName, testID) {

	var theParms = 'toolbar=0,status=0,resizable=1,scrollbars=0,width=300,height=400';
	window.open('/htmlGraphics/cpt_codes.html?testName=' + testName + '&testID=' + testID, 'cptWin', theParms);

}

function getICD9CodesWindow(testName, testID) {

	var theParms = 'toolbar=0,status=0,resizable=1,scrollbars=0,width=300,height=400';
	window.open('/htmlGraphics/icd9_codes.html?testName=' + testName + '&testID=' + testID, 'icd9Win', theParms);

}

function toggle(image, e) {
  var ul = image.parentNode.getElementsByTagName("ul")[0];

  if (image.src.indexOf('down') == -1) {
    ul.style.display = "block";
    image.src = baseDir + '/img/icons/navigation_arrow_down.gif';
  }
  else {
    ul.style.display = "none";
    image.src = baseDir + '/img/icons/navigation_arrow.gif';
  }

  if (e && e.stopPropogation) {
    e.stopPropogation();
  }
  else if (window.event && window.event.cancelBubble) {
    window.event.cancelBubble = true;
  }
}

function getSampleReport(which) {

    if (which== null || which == '') {
        getSampleReport('DME');
    } else {

        if (which == 'DME') {
            window.open('http://www.dnadirect.com/sample_reports/sample_report_2d6Tamoxifen_patients.htm');    
        }


    }

}

/*
*   New B2B pages
*
*/

var approachShown = false;

var approachFrameML =   '<div id="approach_outer_div">' +
                        '<div id="approach_loading"><img src="/img/content_images/reports/reportDNA/aniDNA.gif"><p>Loading Our Approach...</p></div>' +
                        '<iframe frameborder="0" name="approachFrame" id="approachFrame" src="/web/html_graphics/b2b/our_approach.html"></iframe>' +
                        '</div>';

function showApproach() {
    if (!approachShown) {
        //create and show approach frame
        approachShown = true;
        document.getElementById('approachContainer').innerHTML += approachFrameML;
    } else {
        //show the approach frame
        frames.approachFrame.document.body.innerHTML = '';
        frames.approachFrame.document.location.reload();
        document.getElementById('approach_outer_div').style.display = 'block';
    }
}
if (typeof(dna) === "undefined")
  var dna = {};

dna.email = {

  formOptions : {
    'width' : '390',
    'height' : '600',
    'top' : '100',
    'left' : '100',
    'toolbar' : 'no',
    'location' : 'no'
  },

  formOptionsAsString : function() {
    var string = '';
    for(var option in this.formOptions) {
      string += option + "=" + this.formOptions[option] + ",";
    }
    return string.replace(/,$/g,"");
  },

  emailForm : function(url) {
    window.open(url,'_blank',this.formOptionsAsString());
  },

  emailPageLink : function(sendPage, location, title) {
    var stop = title.indexOf("@") == -1 ? title.length() : title.indexOf("@");
    title = title.substring(0, stop);
    var encodedURL = encodeURIComponent(location);
    title = encodeURIComponent(title);
    return sendPage + "?url=" + encodedURL + "&pageTitle=" + title;
  }
}