// These are status codes to be returned by showhide() which will indicate the current status
// of the McKesson drop down.
var MCK_DROP_DOWN_VISIBLE = 1;
var MCK_DROP_DOWN_HIDDEN = 2;

var browser,filteredOs,filteredBrowsers;
var stage1 = 0;
var stage2 = 0;
var flashVersion = 6;
var prefix = "";
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

var plusImage = null;
var minusImage = null;

if ( plugin ) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i) {
		if (isNaN(parseInt(words[i])))
			continue;
		var flashPlug = words[i];
	}
	var gotFlash = flashPlug >= flashVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('gotFlash = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & flashVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

var dropmenuobj;
var noOs = navigator.userAgent.indexOf("Mac") != -1;
var noBrowser = navigator.userAgent.indexOf("Safari") != -1 ;
var noCombo = noOs && navigator.userAgent.indexOf("MSIE") != -1 

if (noBrowser) filter = false;
else if (noCombo) filter = false;
else filter = true;


function openPopup(url,height,width) {
	// check to see if the window is at least 500 wide and 300 high
	if (height == null || height < "300") {
		height="300";
	} else {
		height = height;
	}
	
	if (width == null || width < "500") {
		width="500";
	} else {
		width = width;
	}
	popup = window.open(url,"pop_win","height="+height+",width="+width+",location=no,menubars=no,scrollbars=yes,toolbars=no,resizable=yes")
}
	
function snapT(id,_objName){
	if (document.getElementById) {
		if (document.getElementById(_objName).style.display==''){
			document.getElementById(_objName).style.display='none'
			document.getElementById(id).src= prefix + "/mck/img/pl.gif";
		} else {
			document.getElementById(_objName).style.display=''
			document.getElementById(id).src= prefix + "/mck/img/pm.gif";
		}
	}
}

function setSignup(name,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"=mcksession"+expires+"; path=/";
}

function getSignup(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function checkSignup(signup,name) {
	var signup = escape(signup);
	var theValue = getSignup(name);
	if (!theValue) {
		location.replace(unescape(signup));
	}
}

// place this at the end of the signup process or the success part.
// setSignup(name,days);
// name is the name of cookie
// days is the length of the cookie
// is you remove the days then the cookie will be session based

// to see if the cookie excists use the following
// checkSignup("url","name")
// url is the redirectin URL
// name is the name of the cookie you set above

//var menu1=new Array()
//menu1[0]='<a href="" class="bluelink" onmouseover="empty()">McKesson Pharmaceutical</a>'
//menu1[1]='<a href="" class="bluelink" onmouseover="empty()">McKesson Provider Technologies</a>'
//menu1[2]='<a href="" class="bluelink" onmouseover="empty()">McKesson Medical-Surgical</a>'
//menu1[3]='<a href="" class="bluelink" onmouseover="empty()">McKesson Prescription Systems</a>'
//menu1[4]='<a href="" class="bluelink" onmouseover="empty()">McKesson Pharmacy Systems</a>'
//menu1[5]='<a href="" class="bluelink" onmouseover="empty()">McKesson Health Solutions</a>'
//menu1[6]='<a href="" class="bluelink" onmouseover="empty()">McKesson Specialty</a>'
//menu1[7]='<a href="" class="bluelink" onmouseover="empty()">McKesson Medical management</a>'
//menu1[8]='<a href="" class="bluelink" onmouseover="empty()">Zee Medical</a>'
//menu1[9]='<a href="" class="bluelink" onmouseover="empty()">McKesson International</a>'
//menu1[10]='<a href="" class="bluelink" onmouseover="empty()">View All</a>'

var menuwidth='305px' //default menu width

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
	document.write('<div id="globalnav" style="visibility:hidden;width:'+menuwidth+';background-color:#FFF" onMouseover="empty()" onMouseout="doHide(event)"></div>')

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden){
	if ( (ie4||ns6) && dropmenuobj ) {
		dropmenuobj.style.left=dropmenuobj.style.top=-500
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover") {
		obj.visibility=visible;
		return MCK_DROP_DOWN_VISIBLE;
	}
	else if (e.type=="click") {
		obj.visibility=hidden;
		return MCK_DROP_DOWN_HIDDEN;
	}
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge" && dropmenuobj){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (dropmenuobj && windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) {
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
		}
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-10 : window.pageYOffset+window.innerHeight-18
		
		if (dropmenuobj) {
			dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
			if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){
				edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
				if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) {
					edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
				}
			}
		}
	}
	return edgeoffset
}

function populatemenu(what){
	if ((ie4||ns6) && dropmenuobj)
		dropmenuobj.innerHTML=what.join("")
}

function mckMenu(obj, e, stuff, newPrefix){
	if (newPrefix != null) {
		prefix = newPrefix;
	}
	
	if (window.event)
		event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
		empty()
	
	if (dropmenuobj == null) {
		createImages(prefix);
	}
	
	dropmenuobj=document.getElementById ? document.getElementById("globalnav") : globalnav;
	populatemenu(stuff)
	
	if ((ie4||ns6) && dropmenuobj){
		var dropDownStatus = showhide(dropmenuobj.style, e, "visible", "hidden");
		if (dropDownStatus == MCK_DROP_DOWN_VISIBLE) {
			document.getElementById('icn').src = minusImage.src;
		}
		else {
			document.getElementById('icn').src = plusImage.src;
		}
		
		dropmenuobj.x=getposOffset(obj, "left")-7
		dropmenuobj.y=getposOffset(obj, "top")-1
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	return goThere()
}

function createImages(pPrefix)
{
	plusImage = new Image();
	plusImage.src = pPrefix+'/mck/img/pl.gif';
	minusImage = new Image();
	minusImage.src = pPrefix+'/mck/img/pm.gif';
}

function goThere(){
	if (ie4||ns6) return false
	else return true
}

function doHide(e,prefix){
	if (ie4 && dropmenuobj && !dropmenuobj.contains(e.toElement))
		doHideNow(prefix)
	else if (ns6&&e.currentTarget!= e.relatedTarget)
		doHideNow(prefix)
}

function hideMe(prefix){
	//alert(prefix+'/mck/img/pl.gif');
	document.getElementById('icn').src = plusImage.src;
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6) {
			dropmenuobj.style.visibility="hidden";
		}
	}
}

function doHideNow(prefix){
	delayhide=setTimeout("hideMe('" + prefix + "')",333)
}

function empty(prefix){
	if (typeof delayhide!="undefined") {
		clearTimeout(delayhide);
	}
}

function getSelectedValues(selectElement) {
    var selectedValue;
    for (i=0; i<selectElement.options.length; i++) {
        if (selectElement.options[i].selected) {
            selectedValue = selectElement.options[i].value;
            break;
        }
    }
    return selectedValue;
}

function openCustomerLoginPopup(selectElement) {
    url = getSelectedValues(selectElement);
    if ( url && (url!="") ) {
        window.open(url);
    }
}

function openRequestInfoPopup(urlPrefix,title, email) {
    url = urlPrefix+"/request_info.aspx?title="+title+"&email="+email;
    openPopup(url,'500','600');
}

function openContactUsPopup(urlPrefix,title, email) {
    url = urlPrefix+"/contact_us.aspx?title="+title+"&email="+email;
    openPopup(url,'500','600');
}

function openEventCalendarUrl(urlPrefix) {
    url = urlPrefix+"/event_calendar.aspx";
    document.location.href(url);
}

function openProductsServicesUrl(urlPrefix, buId) {
    url = urlPrefix+"/bu_product_list_body.aspx?buid="+buId;
    document.location.href(url);
}

function openOfferingA2ZUrl(urlPrefix) {
    url = urlPrefix+"/offerings_a2z.aspx";
    document.location.href(url);
}

// Validate content access for a page
// This function is called on the target page for checking on user access
function validateContentAccess4(urlPrefix, from, email, to) {
	var fromURL = null;
	var toURL = null;
	var theURL = "/content_access.aspx";

	if (urlPrefix == null || urlPrefix == "") {
		urlPrefix = "/mck";
	}
	theURL = urlPrefix + theURL;
	if (from != null && from != "") {
		fromURL = from;
	}
	else {
		fromURL = document.referrer;
	}
	if (email == null || email == "") {
		alert("No email address for validateContentAccess().");
		return;
	}
	if (to != null && to != "") {
		toURL = to;
	}
	else {
		toURL = location.href;
	}
	if (location.search == null || location.search == "") {
		theURL += "?";
	}
	else {
		theURL += location.search + "&";
	}
	theURL += "from="+escape(fromURL)+"&email="+email+"&to="+escape(toURL);
	checkSignup(theURL, "McKesson_SignUp");
}

// Validate content access for a page
// This function is called on the target page for checking on user access
function validateContentAccessById(urlPrefix, type, id) {
	var fromURL = document.referrer;
	var toURL = location.href;
	var theURL = "/content_access.aspx";

	if (urlPrefix == null || urlPrefix == "") {
		urlPrefix = "/mck";
	}
	theURL = urlPrefix + theURL;
	if (location.search == null || location.search == "") {
		theURL += "?";
	}
	else {
		theURL += location.search + "&";
	}
	theURL += "from="+escape(fromURL)+"&to="+escape(toURL)+"&type="+type+"&id="+id;
	checkSignup(theURL, "McKesson_SignUp");
}

// validate content access for the current page
function validateContentAccess2(urlPrefix, email) {
	validateContentAccess4(urlPrefix, null, email, null);
}

// validate content access for the current page
function validateContentAccess(email) {
	validateContentAccess4(null, null, email, null);
}

// Email a page
function emailPage(urlPrefix, title, url) {
	var pageTitle = null;
	var pageURL = null;
	var theURL = "/email_page.aspx";

	if (urlPrefix == null || urlPrefix == "") {
		urlPrefix = "/mck";
	}
	theURL = urlPrefix + theURL;
	if (title != null && title != "") {
		pageTitle = title;
	}
	else {
		pageTitle = document.title;
	}
	if (url != null && url != "") {
		pageURL = url;
	}
	else {
		pageURL = location.href;
	}
	theURL += "?title=" + pageTitle + "&page=" + pageURL;
	openPopup(theURL,'400','500');
}

// Email the current page
function emailThisPage() {
	emailPage(null, null, null);
}

function emailThisPage1(urlPrefix) {
	emailPage(urlPrefix, null, null);
}

