/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeFlashS(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '" class="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}


/*

Search Term Highlighter 
Author: Dave Lemen
Version: 0.6

This script highlights searched words on your web page. Since it's implemented 
in JavaScript that runs in the browser, you don't need to do anything special 
on the server. It works in static HTML files as well as dynamically generated
pages.

Here's how to implement it:
1. (Optional) Change the items in the Configuration Section that you want to change.
   There are examples to show you how.
2. Put this file on your web server.
3. Add a script tag to your web page, like this:
	<script type="text/javascript" src="/highlighter.js"></script>
4. Add an "onload" attribute to the body tag, like this:
	<body onload="highlighter.highlight()">
*/

window.highlighter = new SearchTermHighlighter();

// ---------------------------------------------------------------------------
// Configuration Section:
// ---------------------------------------------------------------------------

// Uncomment the following line to hide the legend.
highlighter.legend = false;

// List the URL parameters that contain search terms.
// Defaults: q, as_q, as_epq, as_oq, query, search
// Example:
// highlighter.parameters = 'q, as_q, as_epq, as_oq, query, search';

// Use addStyle(color, background, fontWeight) to change the highlighting style.
// This is optional. A set of 10 default styles will be used automatically.
// Example:
// highlighter.addStyle('#000', '#FF4', 'bold'); // bold, black text on yellow background.
highlighter.addStyle('#555', '#EAEB84', 'normal');
highlighter.addStyle('#555', '#8ED2E3', 'normal');
highlighter.addStyle('#555', '#B1E698', 'normal');

// ---------------------------------------------------------------------------

highlighter.init();

function SearchTermHighlighter()
{
	var ok = ((document.createElement) ? true : false);
	var isInitialized = false;
	var searchTerms = new Array();
	var foundCount = 0;
	var styles = new Array();
	var usingDefaultStyles = true;
	var DEBUG = false;

	this.parameters = 'q as_q as_epq as_oq query search';
	this.legend = true;
	this.addStyle = addStyle;
	this.init = init;
	this.loadSearchTerms = loadSearchTerms;
	this.highlight = highlight;
	this.highlightTerm = highlightTerm;
	this.writeLegend = writeLegend;
	this.hideLegend = hideLegend;
	this.unhighlight = unhighlight;
	
	if (!ok) return;
	loadDefaults();

	function loadDefaults()
	{
		var liteBG = '#FF6 #BFF #9F9 #F99 #F6F'.split(/ /);
		var darkBG = '#800 #0A0 #860 #049 #909'.split(/ /);
		for (var i = 0; i < liteBG.length; i++){styles.push(new HighlightStyle('black', liteBG[i], 'bold'));}
		for (i = 0; i < darkBG.length; i++){styles.push(new HighlightStyle('white', darkBG[i], 'bold'));}
	}

	function addStyle(color, background, fontWeight)
	{
		if (!ok) return;
		if (usingDefaultStyles) { styles = new Array(); usingDefaultStyles = false; }
		styles.push(new HighlightStyle(color, background, fontWeight));
	}

	function init()
	{
		if (!ok) return;
		this.loadSearchTerms();
		var style = 0;
		document.write('<style type="text/css">\n');
		for (i = 0; i < searchTerms.length; i++)
		{
			document.write('.' + searchTerms[i].cssClass + '{' + styles[style] + '}\n');
			style++;
			if (style >= styles.length) style = 0;
		}
		if (this.legend) document.write('#sth_legend{border:1px solid #CCC;background:white;margin:0px;padding:5px;' 
			+ 'font-family:verdana,helvetica,arial,sans-serif;font-size:x-small;}\n');
		document.write('</style>\n');
		isInitialized = true;
	}

	function loadSearchTerms()
	{
		var a = new Array();
		var params = getParamValues(document.referrer, this.parameters);
		var terms;
		var index = 0;
		for (i = 0; i < params.length; i++)
		{
			terms = parseTerms(params[i]);
			for (j = 0; j < terms.length; j++)
			{
				if (terms[j] != '')
				{
					a.push(new SearchTerm(index++, terms[j].toLowerCase()));
				}
			}
		}
		a.sort(function(t1, t2){return ((t1.term == t2.term) ? 0 : ((t1.term < t2.term) ? -1 : 1));});
		var prev = new SearchTerm(0, '');
		for (i = a.length - 1; i >= 0; i--)
		{
			if (a[i].term != prev.term)
			{
				searchTerms.push(a[i]);
				prev = a[i];
			}
		}
		searchTerms.sort(function(t1, t2){return t1.index - t2.index;});
		debugAlert('Search Terms:\n' + searchTerms.join('\n'));
	}
	
	function parseTerms (query)
	{
		var s = query + '';
		s = s.replace(/(^|\s)(site|related|link|info|cache):[^\s]*(\s|$)/ig, ' ');
		s = s.replace(/[^a-z0-9_-]/ig, ' '); // word chars only.
		s = s.replace(/(^|\s)-/g, ' '); // +required -excluded ~synonyms
		s = s.replace(/\b(and|not|or)\b/ig, ' ');
		s = s.replace(/\b[a-z0-9]\b/ig, ' '); // one char terms
		return s.split(/\s+/);
	}

	function getParamValues(url, parameters)
	{
		var params = new Array();
		var p = parameters.replace(/,/, ' ').split(/\s+/);
		if (url.indexOf('?') > 0)
		{
			var qs = url.substr(url.indexOf('?') + 1);
			var qsa = qs.split('&');
			for (i = 0; i < qsa.length; i++) 
			{
				nameValue = qsa[i].split('=');
				if (nameValue.length != 2) continue;
				for (j = 0; j < p.length; j++)
				{
					if (nameValue[0] == p[j])
					{
						params.push(unescape(nameValue[1]).toLowerCase().replace(/\+/g, ' '));
					}
				}
			}
		}
		return params;
	}

	function highlight() 
	{
		if (!ok) return;
		if (!isInitialized) this.init();
		searchTerms.sort(function(term1, term2){return(term2.term.length-term1.term.length)});
		for (var i = 0; i < searchTerms.length; i++)
		{
			this.highlightTerm(document.getElementsByTagName("body")[0], searchTerms[i]);
		}
		if (this.legend)
		{
			this.writeLegend();
		}
	}
	
	function highlightTerm(node, term) 
	{
		// this little step is required to prevent IE from getting wrapped around the axle on 
		// certain types of malformed HTML.
		if (node.nodeType == 1) // element
		{
			if (node.getAttribute("sth_x") == term.term) return;
			else node.setAttribute("sth_x", term.term);
		}
		
		if (node.hasChildNodes())
		{
			for (var i = 0; i < node.childNodes.length; i++) 
			{
				this.highlightTerm(node.childNodes[i], term);
			}
		}

		if (node.nodeType == 3)
		{
			var p = node.parentNode;
			if (p.nodeName != 'TEXTAREA' && p.nodeName != 'SCRIPT' && p.className.substr(0, term.CSS_CLASS_PREFIX.length) != term.CSS_CLASS_PREFIX)
			{
				var result = term.pattern.exec(node.nodeValue);
				if (result != null)
				{
					term.found = true;
					foundCount++;
					var v = node.nodeValue;
					var lt = document.createTextNode(v.substr(0, result.index));
					var rt = document.createTextNode(v.substr(result.index + result[0].length));
					var span = document.createElement('SPAN');
					span.className = term.cssClass;
					span.appendChild(document.createTextNode(result[0]));
					p.insertBefore(lt, node);
					p.insertBefore(span, node);
					p.replaceChild(rt, node);
				}
			}
		}
	}

	function writeLegend()
	{
		if (foundCount > 0)
		{
			var body = document.getElementsByTagName("body")[0];
			var legend = body.insertBefore(document.createElement('DIV'), body.childNodes[0]);
			legend.id = 'sth_legend';
			var s = 'These search terms have been highlighted:';
			searchTerms.sort(function(t1, t2){return t1.index - t2.index;});
			for (var i = 0; i < searchTerms.length; i++)
			{
				if (searchTerms[i].found == true) s += ' <span class="' + searchTerms[i].cssClass + '">' 
					+ searchTerms[i].term + '</span>';
			}
			s += ' | <a href="javascript:void(0);" onclick="highlighter.hideLegend()">hide this legend</a>';
			s += ' | <a href="javascript:void(0);" onclick="highlighter.unhighlight()">remove highlighting</a>';
			legend.innerHTML = s;
		}
	}
	
	function hideLegend()
	{
		var legend = document.getElementById('sth_legend');
		if (legend) legend.parentNode.removeChild(legend);
	}

	function unhighlight()
	{
		var prefix = searchTerms[0].CSS_CLASS_PREFIX;
		var spans = document.getElementsByTagName('SPAN');
		var elts = new Array();
		var parent, i, j;
		for (i = 0; i < spans.length; i++)
		{
			if (spans[i].className.substr(0, prefix.length) == prefix)
			{
				elts.push(spans[i]);
			}
		}
		for (i = 0; i < elts.length; i++)
		{
			parent = elts[i].parentNode;
			for (j = 0; j < elts[i].childNodes.length; j++)
			{
				parent.insertBefore(elts[i].childNodes[j], elts[i]);
			}
			parent.removeChild(elts[i]);
		}
		this.hideLegend();
	}

	function debugAlert(msg){if(DEBUG)alert(msg);}

	function SearchTerm(index, term)
	{
		this.CSS_CLASS_PREFIX = 'sth_';
		this.index = index;
		this.term = term.toLowerCase();
		this.cssClass = this.CSS_CLASS_PREFIX + this.term.replace(/[^a-z0-9_ ]/g, '').replace(/ /g, '_');
		this.pattern = new RegExp('\\b' + this.term + '\\b', 'i');
		this.found = false;
		this.toString = function(){return this.term};
	}

	function HighlightStyle(color, background, fontWeight)
	{
		this.color = color;
		this.background = background;
		this.fontWeight = fontWeight;
		this.toString = function(){return 'color:' + this.color + ';background:' 
			+ this.background + ';font-weight:' + this.fontWeight + ';padding:1px 2px;'};
	}
}




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 MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; 
	obj=document.getElementById(nm); if(obj) if(obj.title) nm=obj.title;
	if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



// jumpmenu
function wJumpMenu(targ,selObj,restore){
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

// open a browser window
function wOpenWindow(url,name,features) {
	window.open(url,name,features);
}

// auto targets
function wSetTargets() {
	var link, checkit, i, l = 0;
	var checkURLs = new Array('/Webnodes');
	while(link = document.links[l++]) { 
		i = 0; 
		while(checkit = checkURLs[i++]) {
			if(link.href.indexOf(checkit) != -1) break;
		}
		if (i>checkURLs.length) link.target = '_blank'; 
	}
}

// submit a form
function wSubmit(obj,action) {
	obj.action = action;
	obj.submit();
}

