//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';
    }
}