//=====================================================================
//  General JavaScript
//=====================================================================

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function emailPage(d)
{
	/*
		hypTitle.Text = Request.QueryString("title")
		litUrl.Value = Request.QueryString("url")
		hypTitle.NavigateUrl = litUrl.Value
		frmFromEmail.Value = Request.QueryString("from")
		frmSubject.Value = Request.QueryString("title")
		frmUrl.Value = Request.QueryString("url")
		*/
	var url = '/utils/send-to-friend.aspx';
	url += '?title='+escape(d.title);
	url += '&url='+escape(d.location.href);
	MM_openBrWindow(url,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=450,height=475');
}

function searchKB(value)
{
	var input = MM_findObj('searchValue');
	if (input!=null)
		value = input.value;
	var url = 'http://kbase.misyshealthcare.com/results.aspx?more=1&ct=Internet..Scope()&ctn=WS&qu='+escape(value)+'&Page=0&Count=1&ct5=Internet..Scope()';
	window.open(url,'_self');
}

//=====================================================================
//  Product Lookup dropdown menu
//=====================================================================

function showProductLookupMenu(link, name, x, y) {
	var menu = MM_findObj(name);
	
	clearProductLookupMenuTimeout()
	if (menu) {
		x = moveXbySlicePos (x, link);
		y = moveYbySlicePos (y, link);
	}
	if (document.layers) {
		if (!menu) return;
		menu.visibility = "inherit";
	} else {
		var s = menu.style;
		s.visibility = "inherit";
		if (x != "relative") {
			s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
			s.left = s.pixelLeft + 'px';
		}
		if (y != "relative") {
			s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
			s.top = s.pixelTop + 'px';
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

function startProductLookupMenuTimeout(name) {
	var hideTimeout = 500;
	var menu = MM_findObj(name);
	if( menu ) {
		window.mmStart = new Date();
		window.mmDHFlag = true;
		window.mmHideMenuTimer = setTimeout("hideProductLookupMenu('"+name+"')", hideTimeout);
	}
}

function clearProductLookupMenuTimeout() {
	clearTimeout(window.mmHideMenuTimer);
}

function hideProductLookupMenu(name) {
	var hideTimeout = 500;
	var menu = MM_findObj(name);
	if (!window.mmDHFlag || !menu) return;
	var elapsed = new Date() - window.mmStart;
	var timeout = hideTimeout;
	if (elapsed < timeout) {
		window.mmHideMenuTimer = setTimeout("hideProductLookupMenu('"+name+"')", timeout+100-elapsed);
		return;
	}
	window.mmDHFlag = false;
	menu.style.visibility = 'hidden';
}

//=====================================================================
//  DOM Image Rollover v3 (hover)
//
//  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
//  Script featured on: Dynamic Drive (http://www.dynamicdrive.com)
//=====================================================================
//  copyright Chris Poole
//  http://chrispoole.com
//  This software is licensed under the MIT License 
//  <http://opensource.org/licenses/mit-license.php>
//=====================================================================

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('IMG');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			if (imgClass[i].match(/imgroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/imgroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1]);
			}
			imgarr[i].onmousedown=function(){
			this.setAttribute('src',this.getAttribute('xsrc'));
				
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'));
			}
		}
	}
}
//Attach load event
if(window.addEventListener){ // Mozilla, Netscape, Firefox
	window.addEventListener('load', domRollover, false);
} else if(window.attachEvent) { // IE
	window.attachEvent('onload', domRollover);
} else {
	window.onload = domRollover;
}
