// medcompnet.com/js/main.js

// Compatible with Safari(v5), IE7+, and Firefox										//
// Designed as a standard library of variables and functions used by most of the pages	//
// in the Frameset website. The variable siteIndex MUST be set to 1 in the /index.html	//
// (frameset) file, as it's integral in the process of re-framing pages that are loaded	//
// independantly of the main frameset.
// * Customizable Variables *
// var myEntity (in main)
// var mailNameAdmin and all other mail[Name|Alias]_* variables (in main)
// var rootExp & domExp (in main - FOR LOCAL SITE ONLY)
// function reframe (url replacement expressions)

// Standard Variables //
var myEntity			= 'Medcomp\u00AE';	// company or website trademark / proper name
var myDisplaySeparator	= '    »   ';	// goes betweem myEntity & message in the status bar
var mailNameAdmin		= 'Eric Harris';
var mailAliasAdmin		= 'webmaster';
var mailNameIntl		= 'Doreen Kibblehouse';
var mailAliasIntl		= 'doreen';
var mailNameDom			= 'Justin Sirna';
var mailAliasDom		= 'jsirna';
var mailNameCS			= 'Customer Service';
var mailAliasCS			= 'cs@medcompir.com';
//var mailNameClinical	= 'Sue Hess';
//var mailAliasClinical	= 'shess';
var mailNameDefault		= mailNameDom;
var mailAliasDefault	= mailAliasDom;
var myDomain;						// NOTE: 'domain' is a reserved word, thus 'myDomain'
var root;							// http document root for nav within JavaScripts
var endURL;							// location.href without the root part
var httpExp			= /^http/i;		// to tell whether we're online or not
var secureExp		= /^https:/;	// to tell whether we're using SSL
var emailExp		= /^[\w.-]{2,}\@[\w.-]{2,}\.([a-z]{2,3}|aero|arpa|coop|info|museum|name)$/
var emptyExp		= /^\s*$/;		// for client-side validation of form fields
var Netscape		= false;		// is Netscape 7.1+ the user-agent?
var IE				= false;		// is IE the user-agent?
var IE6				= false;		// is IE6 the user-agent?
var IE7				= false;		// is IE version less than 8.0? (compatibility mode?)
var Firefox			= false;		// is Firefox the user-agent?
var Safari			= false;		// is Safari the user-agent?
var browser_version	= '';			// app name and number will be filled in by script.
var functions		= 1;			// indicates a frame has loaded this code. (not a PDF window)
var loaded			= false;		// indicates page is completely loaded, (onLoad handler called)
var childWindow		= new Object;	// window name of the messaging pop-up
var mainFrame		= new Object;	// object referencing top.frames[0]
var NetscapeEvent	= new Object;	// see function setNetscapeEvent()
var VAR				= new Object();	// contains key=value pairs from query string
var username;						// if there is a login cookie, username may be displayed
var qStringArgs		= new Array();	// used in creating VAR object
var onload_list		= new Array();
var onscroll_list	= new Array();
var onresize_list	= new Array();


////////////////////////////////////////////////
// Determine Where we are for dynamic linking //
////////////////////////////////////////////////
{
	var rootExp; var domExp;
	if(httpExp.test(location.href)) {
		rootExp	= /^(https?:\/\/[^\/]+\/)\??(.*[^\/]+(\.html)?.*$3?.*$3?.*)$/i;
		domExp	= /^https?:\/\/([\w.-]+\.)?([\w-]+\.[a-z]+)(\:\d+)?\/?$/i;
	} else {	//LOCAL SITE ONLY: Customize the below 2 vars
		rootExp	= /^(.+\/new\.medcompnet.com\/)\??(.*[^\/]+(\.html)?.*$3?.*$3?.*)$/i;
		domExp	= /^(.+)\/(new\.medcompnet.com)\/?$/i;
	}
	
	root		= (location.href).replace(rootExp,"$1");
	endURL		= (location.href).replace(rootExp,"$2");
	myDomain	= root.replace(domExp,"$2");
}

var browserExp = /^.+(MSIE[\s\d\.]+|Chrome\/(\d+\.){3}\d+|\/\d+\.\d+\s+Safari|Firefox\/[\d\.]+$).*/;
browser_version = navigator.userAgent.replace(browserExp, "$1");
browser_version = browser_version.replace(/^[\/\s]+(.*)$/g, "$1");

///////////////////////////////
// Warn IE6 users to upgrade //
///////////////////////////////
if(browser_version.indexOf('MSIE 6') > -1) {
	IE6 = true;
	if(document.cookie.indexOf('old_ie_warned') < 0 && location.href.indexOf('old_ie.html') < 0) {
		var message = 'You are currently using the '+ browser_version +' browser, which is outdated.\n'+
						'Since important features of this site may not function in this browser,\n'+
						'we advise that you upgrade at your earliest convenience.\n\n'+
						'*You are using a popup blocker - please allow popups for this site to\n'+
						'display a list of links to compatible browser upgrades.';
		small_window(root + 'old_ie.html', 320,240, message);
	} else if(location.href.indexOf('old_ie.html') > -1) {
		document.cookie = 'old_ie_warned=1';
	}
}


//////////////////////////////////////////////////////////////////////////////
// Before possibly re-framing, get rid of Netscapes older than appVersion 5 //
//////////////////////////////////////////////////////////////////////////////
if(navigator.appName == 'Netscape') {
	Netscape = true;
	//var version = navigator.appVersion.replace(/^(\d)\.(\d+).*/,"$1$2");
	//if(version < 50) { top.location.replace(root +'old_netscape.html') }
	var version = Number(navigator.userAgent.replace(/^.+Netscape\/([\d\.]+).*$/,"$1"));
	if(version < 7) { top.location.replace(root +'old_netscape.html') }
	
	if(navigator.userAgent.indexOf('Firefox') > -1) {
		Firefox = true;
	} else if(navigator.userAgent.indexOf('Safari') > -1) {
		Safari = true;
	}
} else {
	IE = true;	// we'll just assume
	var version = Number(navigator.userAgent.replace(/^.+MSIE\s+([\d\.]+).*$/,"$1"));
	if(version < 8) {
		IE7 = true;
	}
	document.write('<META HTTP-EQUIV="imagetoolbar" CONTENT="no">');
	document.write('<meta name="MSSmartTagsPreventParsing" content="TRUE">');
}

if(self.location != top.location) {
	top.location.replace(self.location);
	//debug('site is being framed');
}

//////////////////////////////////////////////////////////////////////////////////////
// Format VAR object: query string args of "...html?key1=value&key2=value2&etc..."	//
// will be accessible in JavaScript as VAR.key# -ex:- alert(VAR.key1); => 'value'	//
//////////////////////////////////////////////////////////////////////////////////////
qStringArgs = unescape(location.search).substring(1).split('&');
if(unescape(location.hash).indexOf('?') > -1) {
	var myHash = unescape(location.hash);
	qStringArgs.push(myHash.substring( myHash.indexOf('?')+1 ).split('&'));
}
if(qStringArgs.length > 0) {// && location.search.substring(1).indexOf('=') > -1) {
	for(i=0; i<qStringArgs.length; i++) {
		if(qStringArgs[i] != undefined && String(qStringArgs[i]).indexOf('=') > -1) {
			var key = String(qStringArgs[i]).split('=')[0].replace(/\W/g,'');
			/*var val = unescape(qStringArgs[i].split('=')[1]).replace(/'/g,"\\'");
			val = val.replace(/\n/g, "\\n");
			eval("VAR."+ key +" = '"+ val +"'");*/
			//alert(key+', '+ eval('VAR.'+key));
			var val = unescape(String(qStringArgs[i]).split('=')[1]);
			VAR[key] = val;
		}
	}
	//Take special measures to preserve sub-query strings in 'redirect'//
	if(location.search.substring(1).indexOf('redirect=') > -1) {
		VAR.redirect = location.search.substring(1).replace(/redirect=(.+)$/, "$1");
	}
}

mainFrame = (window.name == 'small_window')? window.opener :
	(top.frames.length > 0)? top.frames[0] : window;
mainFrame.name = 'mainFrame';
//topFrame = top;
//set other frame reference short-cuts as the need arises
// The top doc runs this code before the main frame is loaded, so:
if(top.mainFrame == undefined && mainFrame) { top.mainFrame = mainFrame }


//////////////////////////////////
// Document event handlers::	//
//////////////////////////////////
onload = function() {
	for(var loadIndex=0; loadIndex<=onload_list.length; loadIndex++) {
		eval(onload_list[loadIndex]);
	}
	afterLoad();	//Special onLoad functions to execute after all the rest//
}

onscroll = function() {
	for(var scrollIndex=0; scrollIndex<=onscroll_list.length; scrollIndex++) {
		eval(onscroll_list[scrollIndex]);
	}
}

onresize = function() {
	for(var resizeIndex=0; resizeIndex<=onresize_list.length; resizeIndex++) {
		eval(onresize_list[resizeIndex]);
	}
}

/*if(IE) {
	onfocus = function(){
		//this allows IE to focus on a form fields in the popup window
		//unlike using "onblur=focus()" in the popup
		if(typeof(top.childWindow.document) == 'object') {
			top.childWindow.focus();
		}
	}
}*/
	//////////////////////////////////////////////////////////////////////////////////////////
	// DOCUMENT EVENT HANDLER NOTES::														//
	//////////////////////////////////////////////////////////////////////////////////////////
	// The on*_list arrays are global lists of functions to be called by their respective	//
	// window event handlers. Functions were previously added to handlers by scripts on		//
	//		each page like so:																//
	//		onload2 = onload;																//
	//		onload = function() { onload2(); cutomFunction1(); cutomFunction2(); }			//
	// This would eventaully cause a "stack overflow" because of the recursion involved		//
	// when this code appeared in multiple scripts imported into a single HTML page. Now	//
	// calls like onload_list.push('commands;'); are used by each page to control the flow.	//
	// Note: Any function with a for loop will keep the remaining calls in its on*_list		//
	// array from executing IF a globally-scoped i variable is used, as is the norm. In		//
	// such a case use: on*_list.unshift('func'); to add functions to the end of the list.	//
	//////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////
// Execute these commands at the end of all other onLoad functions (onload_list). //
////////////////////////////////////////////////////////////////////////////////////
function afterLoad() {
	
	//Make all document links display their title attributes in the status bar//
	for(var i=0; i<document.links.length; i++) {
		if(document.links[i].title) {
			var otherOvers = document.links[i].onmouseover;
			if(otherOvers == undefined) { otherOvers = 'void(1);' }
			if(otherOvers.toString().indexOf('function') < 0) { otherOvers = function(){otherOvers} }
			document.links[i].mouseover2 = otherOvers;
			document.links[i].onmouseover = function(){
				setNetscapeEvent();
				this.mouseover2();
				display(this.title);
				return true;
			};
			
			if(Netscape) {//needs a mousout event to clear the status bar
				var otherOuts = document.links[i].onmouseout;
				if(otherOuts == undefined) { otherOuts = 'void(1);' }
				if(otherOuts.toString().indexOf('function') < 0) {
					eval('otherOuts = function(){'+otherOuts+'}');
				}
				//otherOuts = otherOuts.toString().replace(/^[^{]+\{([^}])\}.*$/,"$1");
				document.links[i].mouseout2 = otherOuts;
				document.links[i].onmouseout = function() {
					setNetscapeEvent();
					this.mouseout2();
					window.status = window.defaultStatus;
					//'alert('+otherOuts+');
					return true;
				};
			}
		}
		
		var otherFocus = document.links[i].onfocus;
		if(otherFocus == undefined) { otherFocus = 'void(1);' }
		if(otherFocus.toString().indexOf('function') < 0) { otherFocus = function(){otherFocus} }
		document.links[i].focus2 = otherFocus;
		document.links[i].onfocus = function(){
			this.focus2();
			this.blur();
		};
		
	}
	//END fixing links//
	
	//Take the focus off of form buttons & checkboxes
	for(var i=0; i<document.forms.length; i++) {
		var myForm = document.forms[i];
		for(var j=0; j<myForm.elements.length; j++) {
			var myObj = myForm.elements[j];
			if(myObj.type == 'submit' || myObj.type == 'reset' || myObj.type == 'button' ||
			   myObj.type == 'radio' || myObj.type == 'checkbox') {
				var otherFocus = myObj.onfocus;
				if(otherFocus == undefined) { otherFocus = 'void();' }
				if(otherFocus.toString().indexOf('function') < 0) {
					otherFocus = function(){otherFocus}
				}
				myObj.focus2 = otherFocus;
				myObj.onfocus = function(){
					this.focus2();
					this.blur();
				};
			}
		}
	}
	//END de-focusing buttons//
}


//Center MAIN content vertically//
/*The page bground image is made for a 1024 x 768 screen. Since centering a table on the screen vertically by setting an encapsulating table's height to 100% is not supported, this will resize that table's height up to a maximum dimension, to center the MAIN table on the screen.*/
function adjustLayout() {
	if(!document.getElementById('LAYOUT')) {
		return;
	}
	var pageMaxHeight = 768; //adjust if needed
	var pageHeight = IE? document.documentElement.clientHeight : window.innerHeight;
	//var pageHeight = IE? document.body.offsetHeight : window.innerHeight;
	pageHeight = (pageHeight >= pageMaxHeight)? pageMaxHeight : pageHeight;
	document.getElementById('LAYOUT').style.height = pageHeight +'px';
	
	/*Create a shade layer to cover the content when the drop-down menu is showing*/
	var main = document.getElementById('MAIN');		//main layout table.
	var mainCell = document.getElementById('a0');	//layer won't show in IE if appended to table element
	if(main != null) {
		if(added_shade_layer == 0) {
			added_shade_layer++;
			var divTag = document.createElement("layer");
			divTag.id = 'menu_over';
			//if(IE7) {
				// make sure the cover goes away when clicked on, if the menu's mouseOut event doesn't fire.
				divTag.onclick = function(){document.getElementById('MAIN').className=''};
			//}
			mainCell.appendChild(divTag);
		}
		var rule = 'width:'+ (main.offsetWidth-12) +'px; height:'+
					(main.offsetHeight-52-9) +'px; top:'+ (main.offsetTop+46+9) +'px; left:'+ (main.offsetLeft+6) +'px;';
		var styleTag = document.createElement("style");
		var headTag = document.getElementsByTagName("head")[0];
		headTag.appendChild(styleTag);

		var styleSheet = (styleTag.styleSheet)? styleTag.styleSheet : styleTag.sheet;
		
		// add a new rule to the style sheet
		if(styleSheet) {
			if(styleSheet.addRule) {
				styleSheet.addRule ("#MAIN.menuover #menu_over", rule, 0);
			} else {
				styleSheet.insertRule ("#MAIN.menuover #menu_over {"+ rule +"}", 0);
			}
		}
	}
	
	if(!document.getElementById('c1')) {
		return;
	}
	/*Old IE won't render CSS borders on cells with no contents*/
	if(IE7) {
		var cellIDs = new Array('c1', 'c2');
		var emptyExp = /<\!-- InstanceBeginEditable name="[^"]+" --><\!-- InstanceEndEditable -->/;
		for(var i=0; i<cellIDs.length; i++) {
			var cell = document.getElementById(cellIDs[i]);
			if(cell != null && emptyExp.test(cell.innerHTML)) {
				cell.innerHTML = '&nbsp;';
			}
		}
	}
	/*IE in general won't display the correct cell heights in the main table
	  We have to measure the 1 column (a1, b1, c1) since those are the cells with content
	  and will have different offetHeigth values than a0, b0 and c0. */
	if(IE && document.getElementById('a1')) {
		var abc_height = document.getElementById('abc_height').offsetHeight;
		var a_height = document.getElementById('a1').offsetHeight;
		var b_height = document.getElementById('b1').offsetHeight;
		var c_height = document.getElementById('c1').offsetHeight;
		var actual_height = a_height + b_height + c_height;
		//alert(actual_height +' < '+ abc_height);
		if(actual_height < abc_height) {
			var difference = abc_height - actual_height;
		//alert(b_height +' += '+ difference +' = '+ Number(b_height + difference));
			b_height += difference;
			document.getElementById('b1').style.height = b_height + 'px';
		}
	}
}
var added_shade_layer = 0;
onload_list.push('adjustLayout()');
onresize_list.push('adjustLayout()');


/* Update login/logout links, if necessary. Called from javascript just after the Spry menu. */
if(document.cookie.indexOf('login=') > 0) {
	username = document.cookie.replace(/^.*login=([^;]*);?.*$/, "$1");
}
function login_link() {
	if(top.document.getElementById('login_link') && username) {
		with(top.document.getElementById('login_link')) {
			//innerHTML = 'WELCOME, '+ username.toUpperCase();
			innerHTML = 'Log Out';
			title = 'Log Out, '+ username;
			href = '/logout';
		}
	}
}
function username_link() {
	if(top.document.getElementById('username_cell') && username) {
		with(top.document.getElementById('username_cell')) {
			innerHTML = '<a href="/cgi-bin/members/index.cgi" title="Member tools & settings">'+ username +'</a>';
		}
	}
}


/* Spry menu for main nav breaks in IE 8 because submenus expand their width for some reason, in stead of fitting to the text inside. So the following few id's control the width of each drop-down on a per-menu basis. */
if(IE) {
	function fix_menus() {
		var nav_menus = {'dd_about':'132px',
						 'dd_products':'157px',
						 'dd_news':0,
						 'dd_tradeshows':'113px',
						 'dd_contact':'104px'
						};
		var product_subs = {'lt':'95px',
							'st':'86px',
							'ports':'110px',
							'piccs':'85px',
							'cvc':'95px',
							'pd':'50px',
							'ac':'168px'
						   }
		for(i in nav_menus) {
			if(nav_menus[i] != 0 && document.getElementById(i)) {
				document.getElementById(i).style.width = nav_menus[i];
				var submenus = document.getElementById(i).getElementsByTagName('UL');
				for(ul=0; ul<submenus.length; ul++) {
					submenus[ul].style.marginLeft = nav_menus[i];
					submenus[ul].style.width = product_subs[submenus[ul].id];
				}
			}
		}
	}
	onload_list.push('fix_menus()');
}

/* Set up search form in top nav area. Called by javascript just after search form. */
function initSearch() {
	var searchForm = document.main_search;
	var searchField = searchForm.keywords;
	searchField.onfocus = function(){emptyField(this, 'search')};
	searchField.onblur = function(){emptyField(this, 'search')};
}

//Try to display a message in the window status bar. This may be blocked by the browser.//
window.defaultStatus = myEntity;
function display(message) {
	message = (message == undefined)? '' : myDisplaySeparator + message;
	window.status = myEntity + message;
}


/////////////////////////////////////////////////////////////////////////////////////////
// Navigate from any subframe without having to change target paths to the main frame. //
/////////////////////////////////////////////////////////////////////////////////////////
function nav(x) {
	if(mainFrame == self && mainFrame.relative_nav == true) {
		//var relative_nav MUST be set in the calling document if used at all
		mainFrame.location = x;
	} else {
		mainFrame.location = root + x;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Navigate via POST without hard-coding a form. This keeps query strings etc out of the address bar.	//
// The argument action is a URL, fields is an object like {key:value}, and target is optional.			//
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function post_nav(action, fields, target) {
	var myForm = document.createElement("form");
	target = (target == undefined)? 'mainFrame' : target;
	myForm.target = target;//'_self';//
	myForm.method = "POST";
	myForm.enctype = "application/x-www-form-urlencoded";	//"multipart/form-data";	//"text/plain";	//
	myForm.action = action;
	for(var key in fields) {
		var myInput = document.createElement("input");
		myInput.setAttribute("type", "hidden");
		myInput.setAttribute("name", key);
		myInput.setAttribute("value", fields[key]);
		myForm.appendChild(myInput);
	}
	document.body.appendChild(myForm);
	myForm.submit();
	if(target != self) {
		try {
			document.body.removeChild(myForm);
		} catch(err) {}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// There is no global event object in Netscape as in IE, but an event object is			//
// passed automatically to whatever function each event handler calls. Since our event	//
// handlers pass their own arguments, we need to maintain that separate event object.	//
//////////////////////////////////////////////////////////////////////////////////////////
function setNetscapeEvent(e) { NetscapeEvent = e; }


//////////////////////////////////////////////////////////////////////////////////////////////
// Create a standard pop-up window that can be called dynamically from anywhere in the site //
//////////////////////////////////////////////////////////////////////////////////////////////
function small_window(path,x,y,message,page_name) {
	var iQ = path.indexOf('?');	//find out if path already has a query string//
	path = (path == '')? '' : path;// + ( (iQ > 0 && path.indexOf('=') > iQ)? '&':'?' ) + 'smallwindow=1';
	x = (x == undefined)? 400 : x;
	y = (y == undefined)? 200 : y;
	var message_default = 'You are using a popup blocker,\n'+
							'which is preventing this site from displaying\n'+
							'important information. Please allow popups for\n'+
							'this site in your browser settings.';
	message = (message == undefined)? message_default : message;
	page_name = (page_name == undefined)? 'the requested popup' : page_name;
	var centerV = (screen.height / 2) - (y / 2);
	var centerH = (screen.width / 2) - (x / 2);
	path = (path.indexOf(':')>0 || path == '')? path : root + path;	//allow for "about:blank"
	top.childWindow = window.open(path, "small_window", 'height='+y+',width='+x+
		',left='+centerH+',top='+centerV+',status=0');
	if(top.childWindow) {
		top.childWindow.focus();
	} else {
		alert(message);
		/* The below does not open the window - it just repeats the error message.
		if(document.cookie.indexOf('eharris') > -1 && confirm(message + '\n\nTry again to open '+ page_name +'?')) {
			setTimeout(small_window(path,x,y,message,page_name),100);
		}*/
	}
}


//////////////////////////////////////////////////////////////////////////////////
// The regexps in the object checkFieldTest are to exclude certain characters.	//
// The function is called in the onKeyUp or a similar handler from form fields.	//
//////////////////////////////////////////////////////////////////////////////////
var checkFieldTest = {
	numDigits2	: {replacer: /\D|^(\d{2}).+/g, checker: /\D|^\d{2}.+/},
	numbers		: {replacer: /\D()/g, checker: /\D/},
	noquotes	: {replacer: /["']()/g, checker: /['"]/},
	username	: {replacer: /\W|^[^A-z]+()/g, checker: /\W|^[^A-z]+/},
	email		: {replacer: /[^\w@\-.]()/g, checker: /[^\w@\-.]/} /*|([@\-.])[@\-.]+|^[_@\-.]+/g,
	cc			: /[^\w@\-.,;\s]|([@\-.,;\s])[@\-.,;]+|^[_@\-.,;\s]+/g*/
}
function checkField(field, checkset) {
	checkset = (checkset == undefined)? field.name : checkset;
	var checkExp = eval("checkFieldTest."+checkset+".replacer");
	var newValue = field.value.replace(checkExp, "$1");
	//field.value = field.value.replace(checkExp, "");
	/*if(checkset == 'cc') {	// let the cursor jump to the end of multiple spaces //
		newValue = newValue.replace(/(\s)\s+/, "$1");
	}*/
	
	checkExp = eval("checkFieldTest."+checkset+".checker");
	//Do all this nonesense to make sure the cursor ends up in the same position it started
	if(field.setSelectionRange) { //Netscape
		var caretPosition = field.selectionStart;
		if(checkExp.test(field.value)) { caretPosition-- }
		field.value = newValue;
		field.setSelectionRange(caretPosition, caretPosition);
	} else if(field.createTextRange) { //IE
		//Get cursor position via empty selection range
		var sel = document.selection.createRange();
		//Move selection start to 0 position
		sel.moveStart ('character', -field.value.length);
		//The caret position is selection length
		var caretPosition = sel.text.length
		if(checkExp.test(field.value)) { caretPosition-- }
		field.value = newValue;
		sel.collapse();
		sel.move('character', caretPosition);
		sel.select();
	}
	
}


//////////////////////////////////////////////////////////////////////////////////////////
// Toggle a form field between blank space and some default guide text, like "(email)".	//
// Fields that call this should do so with both onFocus AND onBlur handlers, and have	//
// starting/default values that match the value of guideText, the second argument.		//
//////////////////////////////////////////////////////////////////////////////////////////
function emptyField(field, guideText) {
	if(field.value == guideText) {
		field.value = '';
	} else if(emptyExp.test(field.value)) {
		field.value = guideText;
	}
}


//////////////////////////////////////////////////////////////////////////
// Compose & submit data to the emailer form. Recipients is a space-	//
// delimited list of full email addresses and/or local email aliases.	//
//////////////////////////////////////////////////////////////////////////
function mail(recipients, subject, cc) {
	//alert('main.js:mail function says: '+ recipients +', '+ subject +', '+ cc);
	var page = location.href;
	recipients = (recipients == undefined || recipients == '')? mailAliasDefault : recipients;
	subject = (subject == undefined)? '' : subject;
	if(cc != undefined && cc != '' && !emailExp.test(cc)) {
		cc += '@' + myDomain;
	} else {
		cc = '';
	}
	//nav('cgi-bin/contact/email.cgi?compose=1&recipients=' + escape(recipients) +
	//	'&subject=' + subject + '&cc=' + cc + '&page=' + escape(page));
	//page must be escaped in case it contains a query string//
	var post_obj = {
		'compose':1,
		'recipients':recipients,
		'subject':subject,
		'cc':cc,
		'page':page
	};
	post_nav('/cgi-bin/contact/email.cgi', post_obj);
}


//////////////////////////////////////////////////////////////////////////
// Write-in email links dynamically so email-harvesting spiders can't	//
// get them from the source code. Call with in-line script tag:			//
// document.write( write_email_link('name','alias' [,'emailDomain']) );	//
//////////////////////////////////////////////////////////////////////////
function write_email_link(name, alias, emailDomain, subject, cc, style) {
	name		= (name == undefined || name == '')?				mailNameAdmin	: name;
	alias		= (alias == undefined || alias == '')?				mailAliasAdmin	: alias;
	emailDomain = (emailDomain == undefined || emailDomain == '')?	myDomain		: emailDomain;
	subject		= (subject == undefined)?							''				: subject;
	cc			= (cc == undefined)?								''				: cc;
	style		= (style == undefined)?								'reg'			: style;
	var atOffsiteDomain = '';
	if(emailDomain != myDomain) {
		atOffsiteDomain = '@'+ emailDomain;
	}
/*	return	'<a href="javascript:mail(\''+ name +'\',\''+ alias + atOffsiteDomain +'\',\''+
			subject +'\',\''+ cc +'\');" title="'+ alias +'@'+ emailDomain +
			'" class="'+ style +'">' +
			alias +'@'+ emailDomain +'</a>';*/
	return	'<a href="javascript:mail(\''+ alias + atOffsiteDomain +'\',\''+
			subject +'\',\''+ cc +'\');" title="'+ alias +'@'+ emailDomain +
			'" class="'+ style +'">' +
			alias +'@'+ emailDomain +'</a>';
}


//Launch the social networking bookmark service, or produce the "email page" form//
function shareLink(service, url, title) {
	if(url == undefined) {
		url = String(document.location);
		if(document.location.hash && url.indexOf('#') < 0) {
			url += document.location.hash;
		}
		if(document.videos_form != undefined && document.videos_form.videos_list.length > 1) {
			url += '?video='+ document.videos_form.videos_list.value;
		}
	}
	title = (title == undefined)? document.title : title;
	var path = '';//root+'cgi-bin/contact/share.cgi?service='+service+'&share_url='+escape(url)+'&share_title='+escape(title);
	var target = 'share_window';
	if(top.childWindow.document != undefined) {
		top.childWindow.close();
	}
	if(service == 'email') {
		small_window(path, 260,320);
		top.shareWindow = top.childWindow;
		top.shareWindow.name = target;
	} else {
		top.shareWindow = window.open(path, target);
	}
	//page title must be posted in stead of escaped in case it contains trademark symbols//
	var post_obj = {
		'compose':1,
		'service':service,
		'share_url':url,
		'share_title':title
	};
	post_nav('/cgi-bin/contact/share.cgi', post_obj, target);
}



/////////////////////////////
//Downloading PDF Functions//
var subFrame = false;	//if using download_frame.html

//toggle PDF icon / download details
function toggleDetails(pn, reveal) {//reveal = details|preview
	var resourceDiv = document.getElementById(pn+'_div');
	var sliderDiv = document.getElementById(pn+'_slider_div');
	var previewTable = document.getElementById(pn+'_previewTable');
	var detailsTable = document.getElementById(pn+'_detailsTable');
	//var reveal = (sliderDiv.style.top == '0px')? 'details' : 'preview';
	var startHeight = (reveal == 'details')? 50 : detailsTable.offsetHeight;
	var finishHeight = (reveal == 'details')? detailsTable.offsetHeight : 50;
	var startTop = (reveal == 'details')? 0 : -55;
	var finishTop = (reveal == 'details')? -55 : 0;
	var animationTime = (reveal == 'details')? 500 : 250;
	var steps = (reveal == 'details')? 12 : 6;
	
	easeOut(resourceDiv, 'height', startHeight, finishHeight, animationTime, steps);
	easeOut(sliderDiv, 'top', startTop, finishTop, animationTime, steps);

}


function loading(x) {	//x = hide|show;//
	return;
	
	var layer = top.document.getElementById('downloading');
	if(layer == undefined) { return }
	if(x == 'show' && layer.style.visibility == 'hidden') {
		divLeft = (Netscape)? (top.window.outerWidth / 2) : (top.document.body.clientWidth / 2);
		divTop = (Netscape)? (top.window.innerHeight / 2) + top.window.scrollY :
			((top.document.body.clientHeight / 2) + top.document.body.scrollTop);
		with(layer.style) {
			left = divLeft - (layer.offsetWidth / 2);
			top = divTop - (layer.offsetHeight / 2);
			visibility = 'visible';
		}
		return;
	} else if(x == 'hide' && layer.style.visibility != 'hidden') {
		layer.style.visibility = 'hidden';
		//stop(); //causes error in IE
		//mainFrame.location.reload(false);
	}
}

// GA vars so download function can load the script: //
var google_conversion_id = 0;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "";
var google_conversion_value = 0;

function download(resources,as,zip,targ,dialog,popup,no_prompt) {
	//no_prompt must be an object {} if present.
	//to start an os-dependant "save as" dialog box for this download, set dialog=1//
	var target = (typeof(targ) == 'object')? targ : document;
	if(popup != undefined && typeof(no_prompt) == 'object' && document.cookie.indexOf('no_prompt=') > -1) {
		//working with prompt_val_key values of /brand_name|part_number/
		for(var key in no_prompt) {
			if(emptyExp.test(no_prompt[key])) { break }
			if(document.cookie.indexOf(no_prompt[key]) > document.cookie.indexOf(key)) {
				popup = undefined;
			}
		}
	}
	if(popup != undefined && !username) {
		small_window('',600,600);
		target = childWindow;
	} else {
		//Track download conversion in GA:
		google_conversion_id = 1048708657;
		google_conversion_label = "Cbk4CPPj0QEQsYyI9AM";
		google_conversion_value = 0.25;
		
		var ga = document.createElement('script'); ga.type = 'text/javascript';
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.googleadservices.com/pagead/conversion.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	}
	//var extExp = /\.(pdf|zip)$/;
	//var script = (as == undefined || !extExp.test(as))? 'download.cgi' : as;
	var script = (as == undefined || as == '')? '' : as;
	dialog = (dialog == undefined)? 0 : 1;
	var zipExp = /\.zip/;
	if(zip || zipExp.test(as)) {
		script = script.replace(/\.[^\.]*$/, ".zip");
		zip = 1;
	} else {
		if(dialog == 0){
			loading('show');
		}
		zip = 0;
	}
	
	if(subFrame && target == document && dialog == 0) {
		var framed = '&frame=1';
		nav('products/literature/download_frame.html?'+ root +'cgi-bin/products/literature/'+
			script +'?resources='+ resources +'&archive='+ zip +'&script='+ script + framed);
	} else {
		var url = String(root +'cgi-bin/products/literature/'+ script +'?resources='+
				resources +'&archive='+ zip +'&script='+ script +'&dialog='+ dialog);
		//debug(url);
		target.location = url;
	}
	//as with function reframe(), we want to disable errors caused by code//
	//that is still loaded and responding to mouse events. //
	onerror = function(){return true}
}



var positionExp = /relative|absolute/;
var percent = 0; var newValue = 0;
var intervals = {}; //how many iterations this loop has done for each object being animated
function easeOut(obj, dim, start, finish, time, steps, evt, reSet) {	//alert('easeOut starting...');
	/*
	obj = the HTML object this animation is being applied to
	dim = the CSS property of obj to animate
	start = the starting value of dim
	finish = the value of dim when finished
	time = the total time this animation will take to complete in milliseconds
	steps = how many steps is time split into. I.e., steps/time is like frames/second
	evt = a function call to process when the animation has finished
	interval = how many iterations this loop has done.(Not a passed-in argument)
			   (store a different interval for each oject, so multiple animations can happen at once).
	reSet = true if starting an animation on the same object. This arg is NOT re-inserted into the loop.
	*/
	if(obj == null) {
		return;
	}
	start = Number(start);	//to prevent math errors if this value comes in as a string
	if(typeof(intervals[obj.id]) == "undefined") {
		intervals[obj.id] = {dim:{'interval':0,'currentDir':''}};
	}
	if(typeof(intervals[obj.id][dim]) == "undefined" || reSet) {
		intervals[obj.id][dim] = {'interval':0,'currentDir':''};
	}
	intervals[obj.id][dim].finishedEvent = evt;//function(){eval(evt)};
	if(intervals[obj.id][dim].interval == 0) {
		if(dim == 'opacity') {
			obj.style.opacity = (start / 100); 
			obj.style.MozOpacity = (start / 100); 
			obj.style.KhtmlOpacity = (start / 100); 
			obj.style.filter = "alpha(opacity=" + start + ")";
		} else {	//alert('assigning start value of '+ start +'px');
			obj.style[dim] = start +'px';
			if(IE7 && !positionExp.test(obj.style.position)) {/*Old IE won't hide the overflow unless position is set*/
				intervals[obj.id][dim].IE7_position = obj.style.position;
				obj.style.position = 'relative';
			}
		}
	} else if(intervals[obj.id][dim].interval != steps) {
		if((start < finish && intervals[obj.id][dim].currentDir == 'down') ||
			(start > finish && intervals[obj.id][dim].currentDir == 'up')) { //switching directions
			intervals[obj.id][dim].interval = (steps - intervals[obj.id][dim].interval);
			clearTimeout(intervals[obj.id][dim].timerID);
		}
	}
	
	intervals[obj.id][dim].interval++;
	var x = (1/time) * (time/steps) * intervals[obj.id][dim].interval;
	if(start < finish) {
		intervals[obj.id][dim].currentDir = 'up';
		//var percent = .5*(sin(x * Math.PI - Math.PI/2)+1);
		percent = (2-x)*x;
		newValue = 0 + start + (percent * (finish - start));
	} else {
		intervals[obj.id][dim].currentDir = 'down';
		percent = (2-x)*(-x)+1;
		newValue = Number(finish + (percent * (start-finish)));
		//alert('start:'+start+', finish:'+finish+', percent:'+percent+', newValue:'+newValue);
		//var newValue = 0 + (((start - finish) * percent) + finish); //same thing
	}
	if(dim == 'opacity') {	//alert('fading '+ intervals[obj.id][dim].currentDir);
		obj.style.opacity = newValue/100; 
		obj.style.MozOpacity = newValue/100; 
		obj.style.KhtmlOpacity = newValue/100; 
		obj.style.filter = "alpha(opacity=" + newValue + ")";
	} else {	//alert('moving '+ intervals[obj.id][dim].currentDir);
		if(dim == 'scale') {
			obj.style.width = newValue +'px';
			obj.style.height = newValue +'px';
		} else {
			obj.style[dim] = newValue +'px';
		}
		if(newValue>1000){/*alert('going '+ intervals[obj.id][dim].currentDir +': '+ obj.style[dim]);*/ return;}
	}
	if(intervals[obj.id][dim].interval == steps) {
		if(IE && dim == 'opacity' && intervals[obj.id][dim].currentDir == 'up') {
			//obj.style.filter = "";//<-works, but causes gradient overlay to become 100% opaque
			//-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=100)";//<-doesn't work
		}
		if(IE7 && dim != 'opacity' && obj.style.position == 'relative') {
			/*Since Old IE won't hide the overflow unless position is set*/
			if(intervals[obj.id][dim].IE7_position != undefined && intervals[obj.id][dim].IE7_position != '') {
				obj.style.position = intervals[obj.id][dim].IE7_position; //reset to original value
			}
			/*if(intervals[obj.id][dim].IE7_position != '') {
				obj.style.position = intervals[obj.id][dim].IE7_position; //reset to original value
				alert('setting '+obj.id+' to '+intervals[obj.id][dim].IE7_position);
			} else if(obj.className == 'hidden') {
				alert('setting '+obj.id+' to absolute');
				obj.style.position = 'absolute';
			} else {
				//just leave it relative//obj.style.position = '';
				alert('leaving '+obj.id+' at relative');
			}*/
		}
		intervals[obj.id][dim].interval = 0;
		intervals[obj.id][dim].currentDir = '';
		eval(intervals[obj.id][dim].finishedEvent);
		return;
	}
	
	clearTimeout(intervals[obj.id][dim].timerID);
	intervals[obj.id][dim].timerID = setTimeout(function(){ easeOut(obj, dim, start, finish, time, steps, evt) }, time/steps);
}

//pass commands to an embedded Flash file with id=flashId
function tellFlash(flashId, commands) {
	var flashObj = IE? window[flashId] : window.document[flashId];
	if(flashObj == undefined) {
		flashObj = window.document[flashId];
	}
	if(flashObj) {
		eval("flashObj."+ commands);
	}
}


//Google Analytics for main window pages:
var gaCustomVars = {	//indexes 1-5
	1:'member_type',
	2:'member_id'
};
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12572967-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
function initGoogleAnalytics() {
	//user-defined or custom variables: [ _setVar('value') || _setCustomVar(index, name, value, opt_scope) ]
	//see: http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
	for(var i in VAR) {
		if(RegExp(/^utm_cv/).test(i)) {
			var num = i.replace(/^utm_cv(\d)$/, "$1");
			_gaq.push(['_setCustomVar', num, VAR[i], gaCustomVars[num], 1]);
			//debug(i +': '+ gaCustomVars[num] +'='+ VAR[i]);
		}
	}
	//END custom variables
	
	_gaq.push(['_trackPageview']);
	
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}
onload_list.push("initGoogleAnalytics()");
//END Google


//Start Kampyle Exit-Popup Code
var k_push_vars = {
    "display_after": 60,
	"view_percentage": 5,
	"popup_font_color": "#000000",
	"popup_background": "#ffffff",
	"popup_separator": "#D4E2F0",
	"header": "Your feedback is important to us!",
	"question": "Would you be willing to give us a short (1 minute) feedback?",
	"footer": "Thank you for helping us improve our website",
	"remind": "Remind me later",
	"remind_font_color": "#3882C3",	
	"yes": "Yes",
	"no": "No",
	"text_direction": "ltr",
	//"images_dir": "http://cf.kampyle.com/",
	"images_dir": "/images/",
	"yes_background": "#76AC78",
	"no_background": "#8D9B86",
	"site_code": 2029488
}
document.write('<link rel="stylesheet" type="text/css" media="screen" href="/css/k_button.css">');
function insert_kampyle() {
	//return secureExp.test(location.href)? '' :
	return '<div><a href="'+document.location.protocol+'//www.kampyle.com/solutions/customer-feedback-form/"  target="kampyleWindow" id="kampylink" class="k_float k_bottom_sl k_left" onclick="javascript:k_button.open_ff(\'site_code=2029488&lang=en&form_id=42828\');return false;"><img id="kampyle_btn" src="/images/spacer.gif" alt="CustomerFeedback" width="81" height="81" border="0"></a></div>'+
	'<script type="text/javascript" src="/js/k_button.js"></script>'+
	'<script type="text/javascript" src="/js/k_push.js"></script>';
}
//End Kampyle//

//Function for testing & debug scripts on a production site//
function debug(x) {
	if(document.cookie.indexOf('eharris') > -1) {
	   //alert(x);
	   return prompt('Debug:', x);
   }
}
