/**
 * by David Milner, September 2005
 * Copyright (c) 2005 by Spectrum Chromatography
 *
 * Spectrum grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

// starthere


var j_TopImage;
var j_TopLastOver;
var j_TopMenuUp = -1;
var j_TopMenuSpans = Array ();
var j_TopCloseTimer;
var j_TopCloseTime = 1500;

function $ (name) {
	return document.getElementById (name);
}

function DebugMsg (msg) {
	var dv = document.getElementById ('DebugDiv');
	dv.innerHTML += msg + '<br />\n';
}

function j_TopMenuOff () {
	try {
		if (j_TopImage) j_TopImage.src = j_TopImage.src.replace (/_hil/, '');
		j_TopImage = undefined;
		j_TopMenuUp = -1;
		var dv = $('topmenu');
		dv.style.visibility = 'hidden';
		dv.daveContent = false;
	} catch (e) { ; }
}

function j_TopMenuStart (Timg, Twhich) {
	j_TopStopClose ();

	if (typeof(j_LCloseAll) == 'function') j_LCloseAll();
	if (typeof(MClose) == 'function') MClose();

	if (Twhich == j_TopMenuUp) {
		j_TopUnhilite ();
		j_TopLastOver = 0;
		return;
	}

	j_TopMenuOff();

	if (Twhich == 1) {
		j_PopUpCart (Timg);
		return;
	}
	
	if (Twhich == 1 ||
	    Twhich == 5 ||
	    Twhich == 6) return;

	j_TopMenuUp = Twhich;
	var dv = $('topmenu');
	j_TopImage = Timg;

	try {
		var mSession = '';
		var aret = '';
		try {
			if (typeof(FromName == 'string')) aret = FromName;
			if (!aret.length) aret = document.title;
			var afrom = window.location;
			aret = '?FrName='+escape(aret)+';LiFrom='+escape(afrom)+';'
		} catch (e) { aret=''; }
		if (typeof(session)!='undefined' && session.length) mSession = '?Ses='+session+';';
		var entries = ["Ordering",	    "e-mail links",	 "facilities",	    "distributors",	    "lit request",	  "How are we doing?"];
		var links   = ["/generic/phone.html", "/generic/emails.html", "/generic/contact.html", "/i18n/distributors.html", "/generic/litreq.html", "/generic/Survey.html"+aret];
		if (typeof(TopMenuOffset) == 'undefined') dv.style.top = '55px';
		else dv.style.top = ''+(55+TopMenuOffset)+'px';
		dv.style.left = '497px';
		var width = 110;
		if (Twhich == 3) {
			entries = ["company profile",       "press center",	   "executive bios",     "job opportunities",  "art collection",    "Privacy Policy",        "Terms &amp; Conditions", "Site FAQ's",            "Copyright Info"];
			links   = ["/generic/profile.html", "/generic/press.html", "/generic/bios.html", "/generic/jobs.html", "/generic/art.html", "/generic/privacy.html", "/generic/terms.html",    "/generic/Welcome.html", "/generic/copyrite.html"];
			width = 115;
			dv.style.left = '583px';
		}
		if (Twhich == 4) {
			entries = ["Catalogs &amp; Publications", "Product Brochures",   "Instructions for Use",   "Applications Notes", "Technical Information", "MSDS",	   "Quality Documents", "Chemical Compatibility"];
			links   = ["/lit/catalogs.html",	  "/lit/brochures.html", "/lit/instructions.html", "/lit/appnotes.html", "/lit/tech.html",	"/lit/msds.html", "/lit/quality.html", "/cell/Compatibility.html"];
			width = 133;
			dv.style.left = '670px';
		}
		var ins = '';
		var ix;
		for (ix=0; ix<entries.length; ix++) {
			if (ix == entries.length-1) ins += '<div id="J_TOPMENU'+ix+'" class="topmenuitem1" ';
			else			    ins += '<div id="J_TOPMENU'+ix+'" class="topmenuitem" ';
			ins +=	' onMouseOver="j_TopSMenuOver(this, '+ix+');" onMouseOut="j_TopSMenuOut(this, '+ix+');" onClick="j_TopMenuClick(\''+window.top.location.protocol+'//'+window.location.hostname+j_Foffset+links[ix]+mSession+'\');">'+
				'<a href="'+window.top.location.protocol+'//'+window.location.hostname+j_Foffset+links[ix]+mSession+'" class="topmenu" target="_top"><nobr>'+entries[ix]+'</nobr></a></div>';
		}
		dv.innerHTML = ins;
		dv.daveContent = Twhich;
		dv.style.visibility = 'inherit';
		dv.style.zIndex = 39;
		dv.style.width = width + 'px';
	} catch(e) {; }
}

function j_TopMenuOut (TArea, Twhich) {
	j_TopStartClose();
}

function j_TopSMenuOver (dv, cnt) {
	j_TopStopClose();
	if (typeof(j_TopLastOver) != 'undefined' && j_TopLastOver.id && j_TopLastOver.id != dv.id) j_TopUnhilite();
	if (cnt >= 0) {
		dv.style.backgroundColor = '#FF9800';
		j_TopLastOver = dv;
	}
	s = j_TopImage.src;
	if (!s.match(/_hil/)) {
		j_TopImage.src = s.replace (/(\.[^\/]+)$/, '_hil$1');
	}
}

function j_TopSMenuOut (dv, cnt) {
	j_TopStartClose();
	j_TopUnhilite();
}

function j_TopUnhilite () {
	if (typeof(j_TopLastOver) != 'undefined' && j_TopLastOver.style) {
		j_TopLastOver.style.backgroundColor = 'white';
	}
}

function j_TopMenuClick (where) {
	window.top.location = where;
}

function j_TopStartClose() {
	j_TopStopClose();
	j_TopCloseTimer = setTimeout ("j_TopCloseUp();", j_TopCloseTime);
}

function j_TopStopClose() {
	if (j_TopCloseTimer != 0) clearTimeout(j_TopCloseTimer);
	j_TopCloseTimer = 0;
}

function j_TopCloseUp () {
	try {
		if (j_TopImage) j_TopImage.src = j_TopImage.src.replace (/_hil/, '');
		j_TopStopClose();
		var dv = $('topmenu');
	        dv.daveContent = false;
		j_TopMenuUp = -1;
		dv.style.visibility = 'hidden';
		dv.innerHTML = ' ';
		dv.style.zIndex = 1;
	} catch (e) { ; }
}

function j_PopUpCart (Timg) {
	j_PopUpCartInt (Timg, 'J_PUCld');
}

function j_PopUpCartBottom () {
	j_PopUpCartInt (undefined, 'J_PUCldBot');
}

function j_PopUpCartInt (Timg, lode) {
	var dv = $('topmenu');
	if (dv.daveContent == 'cart') return;
	dv.daveContent = 'cart';
	var mSession = '';
	if (typeof(session)!='undefined' && session.length) mSession = '?Ses='+session+';';
	if (typeof(TopMenuOffset) == 'undefined') dv.style.top = '55px';
	else dv.style.top = ''+(55+TopMenuOffset)+'px';
	dv.style.left = '405px';
	
	var aret = '';
	if (typeof(FromName == 'string')) aret = FromName;
	if (!aret.length) aret = document.title;
	var afrom = window.location.pathname;
	aret = 'FrName='+escape(aret)+';LiFrom='+escape(afrom)+';'
	
	if (!mSession.length) mSession = '?'
	mSession += aret;

	var m = '<iframe id="j_Aframe" src="/mshop/ShowMiniCart/index.html'+mSession+'"  FRAMEBORDER="0" SCROLLING="no" onclick="MClose();" style="width:auto; height:auto;" onload="'+lode+'(this);"></iframe>' +
		'<div id="j_smcoverlay" style="position:absolute; top:0px; left:0px; width:2px; height:2px; '+
		'background-color:transparent;" onclick="j_PUCxit();" onmouseover="j_TopSMenuOver(this, -1);" onmouseout="j_TopSMenuOut(this, 1);"> </div>';

	dv.innerHTML = m;
	dv.style.visibility = 'hidden';
	dv.style.zIndex = 39;
	
	j_TopImage = Timg;
}

function J_PUCld(frm) {
	var dv = $('topmenu');
	var dc = false;
	var width = false;
	var height = false;
	var noshow = false;

	try {
		var vset = false;
		if (frm.content && frm.contentDocument.body) {
			dc = frm.contentDocument.body;
			if (dc && dc.clientHeight) {
				width  = dc.clientWidth;
				height = dc.clientHeight;
				noshow = noshow || j_PUCns(dv);
				vset = true;
			}
			var ac = frm.contentDocument.document.getElementById ('PUCtab');
 			if (ac && ac.clientHeight) {
				width  = ac.clientWidth;
				height = ac.clientHeight;
				noshow = noshow || j_PUCns(ac);
				vset = true;
			}
		}
		if (!vset && frm.contentWindow && frm.contentWindow.document && frm.contentWindow.document.body) {
			dc = frm.contentWindow.document.body;
			if (dc && dc.scrollHeight) {
				width  = dc.clientWidth;
				height = dc.clientHeight;
				noshow = noshow || j_PUCns(dc);
				vset = true;
			}
			var ac = false;
			if (frm.contentWindow.document.getElementById) ac = frm.contentWindow.document.getElementById ('PUCtab');
			if (ac && ac.scrollHeight) {
				width  = ac.clientWidth;
				height = ac.clientHeight;
				noshow = noshow || j_PUCns(ac);
				vset = true;
			}
		}
	} catch (e) {return;}

	if (width) {
		frm.style.paddingLeft  = '5px';
		frm.style.paddingRight = '5px';
		if (dv) dv.style.width  = width + 'px';
		frm.style.width = (width + 10) + 'px';
	}
	if (height) {
	        if (dv) dv.style.height  = height + 'px';
	 	frm.style.height = (height + 10) + 'px';
	}
	var dv = frm.offsetParent;
	dv.style.border='none';
	dv.style.backgroundColor = '#F8F8F8';
	dv.style.height = '' + (frm.offsetHeight) + 'px';
	if (!noshow) { dv.style.visibility = 'inherit'; }

	var dv = $('j_smcoverlay');
	if (dv) {
	        dv.style.width  = (width +10) + 'px';
	        dv.style.height = (height+10) + 'px';
	}
}

function j_PUCns (dv) {
	try {
		if (dv.innerHTML.match (/<!-- DONT SHOW --/)) return true;
	} catch (e) { ; }
	return false;
}

function j_PUCxit () {
	var img = $('CartButton');
	var par = img.parentNode;
	if (par.nodeName != 'A') return;
	
	window.top.location = par.href;
	return;
}


// phone.js

function phclick (lnk) {
	return true;
}

function j_PhCommon (dv, Timg, offtop, offleft) {
	dv.style.zIndex = 39;
	var top  = Timg.offsetTop;
	var left = Timg.offsetLeft;
	var x = Timg.offsetParent
	while (x) {
		top += x.offsetTop;
		left += x.offsetLeft;
		x = x.offsetParent;
	}
	x = dv.offsetParent;
	while (x) {
		top -= x.offsetTop;
		left -= x.offsetLeft;
		x = x.offsetParent;
	}
	dv.style.top = (top-offtop)+'px';
	dv.style.left = (left+offleft)+'px';
	dv.style.visibility = 'inherit';
}

function j_CardStart () {
	var Timg = j_j_PhStart (101);
	if (!Timg) return;

	var dv = $('topmenu');
	var msg = 'Click here to register to shop<br>';
	if (Timg.name && Timg.name.length) msg += '<b>'+Timg.name+'% discount for credit card orders<br>placed on-line</b>';
	dv.innerHTML = '<div style="border:thin solid black; padding:5px; background-color:#F0F0F0;"  onmouseover="j_TopStopClose();" onmouseout="j_TopStartClose();" onclick="j_PhRegClick();">'+
	        msg +
		'</div>';
	dv.daveContent = 101;
	j_PhCommon (dv, Timg, 55, 70);
	dv.style.width = '240' + 'px';
}

function j_PhRegClick () {
	var mSession = '';
	if (typeof(session)!='undefined' && session.length) mSession = '?Ses='+session+';';
	window.top.location = window.location.protocol+'//'+window.location.hostname+'/mshop/register/index.html'+mSession;
}

function j_POStart () {
	var Timg = j_j_PhStart (102);
	if (!Timg) return;

	var dv = $('topmenu');
	var msg = 'Click here to register to shop<br>';
	if (Timg.name && Timg.name.length) msg += '<b>Free ground shipping for orders placed on-line</b>';
	dv.innerHTML = '<div style="border:thin solid black; padding:5px; background-color:#F0F0F0;"  onmouseover="j_TopStopClose();" onmouseout="j_TopStartClose();" onclick="j_PhRegClick();">'+
	        msg +
		'</div>';
	dv.daveContent = 102;
	j_PhCommon (dv, Timg, 55, 253);
	dv.style.width = '240' + 'px';
}

function j_j_PhStart (Num) {
	var Timg = $('CCstrip');
	if (Timg) {
		j_TopStopClose ();
		if (typeof(j_LCloseAll) == 'function') j_LCloseAll();
		if (typeof(MClose) == 'function') MClose();
		j_TopMenuOff();
       		j_TopMenuUp = Num;
		j_TopImage = undefined;
	}
	return Timg;
}

function j_PhMenuStart () {
	var Timg = j_j_PhStart (100);
	if (!Timg) return;

	var dv = $('topmenu');
	dv.innerHTML = '<div style="border:thin solid black; padding:5px; background-color:#F0F0F0;" onmouseover="j_TopStopClose();" onmouseout="j_TopStartClose();" onclick="j_PhCopyKlik();">'+
		'<table><tr><td>US &amp; Canada:</td><td>1-800-634-3300</td></tr>'+
		'<tr><td>Chromatography:</td><td>1-800-459-9700</td></tr>'+
		'<tr><td>OR Disposables:</td><td>1-888-349-1750</td></tr>'+
		'<tr><td>Europe:</td><td>+31 (0) 76 5719 419</td></tr>'+
		'<tr><td>Japan & Asia:</td><td>+81 (0) 77 578 0166</td></tr></table>'+
		'<b>Click for additional contact information</b></div>';
	dv.daveContent = 100;
	j_PhCommon (dv, Timg, 110, 540);
	dv.style.width = '240' + 'px';
}

function j_PhMenuOut () {
	j_TopStartClose();
}

function j_PhCopyKlik () {
	var mSession = '';
	if (typeof(session)!='undefined' && session.length) mSession = '?Ses='+session+';';
	window.top.location = window.location.protocol+'//'+window.location.hostname+'/generic/contact.html'+mSession;
}

function J_PUCldBot(frm) {
	var tm = $('topmenu');
	var dc = false;
	var width = false;
	var height = false;
	var noshow = false;
	var Timg = $('CCstrip');
	if (!Timg) return;

	try {
		var vset = false;
		if (frm.content && frm.contentDocument.body) {
			dc = frm.contentDocument.body;
			if (dc && dc.clientHeight) {
				width  = dc.clientWidth;
				height = dc.clientHeight;
				noshow = noshow || j_PUCns(tm);
				vset = true;
			}
			var ac = frm.contentDocument.document.getElementById ('PUCtab');
 			if (ac && ac.clientHeight) {
				width  = ac.clientWidth;
				height = ac.clientHeight;
				noshow = noshow || j_PUCns(ac);
				vset = true;
			}
		}
		if (!vset && frm.contentWindow && frm.contentWindow.document && frm.contentWindow.document.body) {
			dc = frm.contentWindow.document.body;
			if (dc && dc.scrollHeight) {
				width  = dc.clientWidth;
				height = dc.clientHeight;
				noshow = noshow || j_PUCns(dc);
				vset = true;
			}
			var ac = false;
			if (frm.contentWindow.document.getElementById) ac = frm.contentWindow.document.getElementById ('PUCtab');
			if (ac && ac.scrollHeight) {
				width  = ac.clientWidth;
				height = ac.clientHeight;
				noshow = noshow || j_PUCns(ac);
				vset = true;
			}
		}
	} catch (e) {return;}

	if (width) {
		frm.style.paddingLeft  = '5px';
		frm.style.paddingRight = '5px';
		if (tm) tm.style.width  = width + 'px';
		frm.style.width = (width + 10) + 'px';
	}
	if (height) {
	        if (tm) tm.style.height  = height + 'px';
	 	frm.style.height = (height + 10) + 'px';
	}
	var dv = frm.offsetParent;
	dv.style.border='none';
	dv.style.backgroundColor = '#F8F8F8';
	dv.style.height = '' + (frm.offsetHeight) + 'px';
	if (!noshow) { dv.style.visibility = 'inherit'; }

	var dv = $('j_smcoverlay');
	if (dv) {
	        dv.style.width  = (width +10) + 'px';
	        dv.style.height = (height+10) + 'px';
	}
//function j_PhCommon (dv, Timg, offtop, offleft) {
	var topoff = 100;
	if (height) topoff = height + 5;
	j_PhCommon (tm, Timg, topoff, 400);
}


