//if scripting is disabled these following styles will not be read.
document.write('<link href="/includes/noscript.css" rel="stylesheet" type="text/css">');

/* This handy function from Simon Willison allows you to stack up 'window.onload' events <br />
without them stepping on each other's toes. It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
	/*
	 * cssjs
	 * written by Christian Heilmann (http://icant.co.uk)
	 * eases the dynamic application of CSS classes via DOM
	 * parameters: action a, object o and class names c1 and c2 (c2 optional)
	 * actions: swap exchanges c1 and c2 in object o
	 *			add adds class c1 to object o
	 *			remove removes class c1 from object o
	 *			check tests if class c1 is applied to object o
	 * example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
	 */
	function cssjs(a,o,c1,c2)
	{
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;

		}
	}

/**********
xhtml1.1 valid replacement for target="_blank"
Also a Savvy way to do popup windows
*********/
/* This is our old popup code - parts of the site still use it, so I need to keep it */
function acpopup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,scrollbars=yes,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}
/* new accessible, unobtrusive popup code */
function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
		 if (relIndex){
		 var relSplit = relIndex.split("|");
/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {
            anchor.target = "_blank";
			anchor.className = "external";
			anchor.title = "Load in new window: "+ anchor.href;
/* XHTML compliant popup attribute */
   			} else if (relSplit[0] == "popup") {
			anchor.className = "popup";
			anchor.title = "Link loads in Popup Window";
			anchor.popupWidth = relSplit[1];
			anchor.popupHeight = relSplit[2];
	        anchor.onclick = function() {acpopup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			}
		}
	}
}
addLoadEvent(function() {
	windowLinks();	
});


//Exit Survey Popup script on exit.
//Begin
var expDays = 15; // number of days the cookie should last
var page = "/exitSurvey.php";
var windowprops = "toolbar=no,width=616,height=680,resizable=no,bgcolor=#000000,scrollbars=yes";

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : '/';
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
	var count = GetCookie('count')
	if(count == null) {
		SetCookie('count','1')
		return 1
	}else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

var surveyFlag = GetCookie('exitSurvey');
var takenSurvey = GetCookie('takenSurvey');
function exitSurvey() {
/*
be sure to place the following in the body tag to turn exit surveys back on:
onunload="exitSurvey();"
and uncomment the behavior.register code for exitSurveyRules
*/
/*
	if(takenSurvey!=1 && surveyFlag!=1 && iLink!=1) { 
		//alert(GetCookie('exitSurvey'));
		SetCookie('exitSurvey', 1, exp);
		window.open(page, "", windowprops);
	}
*/
}
var iLink = 0;
function flagInternalLink(){
	iLink = 1;
}

function openDatasheetPopUp( ltype,page )
{
	if (ltype == 1) {
		url = "/products/popup_datasheet.php?option_id=" + page + "";	
	} else if (ltype == 2 ) {
		url = "/products/popup_datasheet.php?id=" + page + "";	
	}
	features = "toolbar=no,width=616,height=600,resizable=no,bgcolor=#000000,scrollbars=yes";
	window.name="MyWindow";
	window.open( url, "", features );
}

function openNewsPrinterFriendly(page )
{
	url = "/news/press_releases_printer_friendly.php?id=" + page + "";	
	features = "toolbar=no,width=616,height=600,resizable=no,bgcolor=#000000,scrollbars=yes";
	window.name="MyWindow";
	window.open( url, "", features );
}


