function o(url, w, h, name) {
	options = "toolbar=no,scrollbars=no,resizable=yes,alwaysRaised=yes,status=no,height=" + h + ",width=" + w;
	p=window.open(url, name, options);
	p.focus();
}

function checkall(frmName) {
	frm = document.forms[frmName];
	
	for (i=0; i<frm.elements.length; i++) {
		if (frm.elements[i].type == "checkbox") {
			if (frm.elements[i].checked) {
				frm.elements[i].checked = false;
			} else {
				frm.elements[i].checked = true;
			}
		}
	}
}

function fe(id) {
	if (document.all && !document.getElementById) {
		e = eval("document.all." + id);
	} else if (document.getElementById) {
		e = document.getElementById(id);
	} else {
		e = false;
	}
	return e;
}

function fl(d) {
	e = fe("feed");
	if (d==0) {
		e.style.display = "none";
	} else {
		e.style.display = "";
	}
}

var currentTextArea;
var selectedRange;

function saveCursor(ta) {
	currentTextArea = ta;
	
	if (ta.createTextRange){
		selectedRange = document.selection.createRange().duplicate();
	}
}

var browserAgent = navigator.userAgent.toLowerCase();
var browserVersion = parseInt(navigator.appVersion);
var is_ie = ((browserAgent.indexOf("msie") != -1) && (browserAgent.indexOf("opera") == -1));
var is_win = ((browserAgent.indexOf("win")!=-1) || (browserAgent.indexOf("16bit") != -1));

function c(text, tags) {
	if (window.currentTextArea){
		var ta = currentTextArea;
		
		if (tags) {
			textStart = '['+text+']';
			textEnd = '[/'+text+']';
		} else {
			textStart = '';
			textEnd = text;
		}
		
		if ((browserVersion >= 4) && is_ie && is_win) {
			curentSelection = document.selection.createRange().text;
			if (curentSelection) {
				document.selection.createRange().text = textStart + curentSelection + textEnd;
				curentSelection = '';
				ta.focus();
				return;
			}
		
		} else if (ta.selectionEnd && (ta.selectionEnd - ta.selectionStart > 0)) {
			end = ta.selectionEnd;
			if (end == 1 || end == 2) end = ta.textLength;
			ta.value = (ta.value).substring(0, ta.selectionStart) + textStart + (ta.value).substring(ta.selectionStart, end) + textEnd + (ta.value).substring(end, ta.textLength);
			return;
		}
		
		if (ta.createTextRange && selectedRange) {
			selectedRange.text += textStart + textEnd;
		
		} else if (ta.selectionStart || ta.selectionStart == '0') {
			ta.value = ta.value.substring(0, ta.selectionEnd) + textStart + textEnd + ta.value.substring(ta.selectionEnd);
		
		} else {
			ta.value += textStart + textEnd;
		}
		ta.focus();
	}
}

function halogo(images) {
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

	if (plugin) {
		plugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1)) >= 4;
	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)) {
		document.write('<script language="VBScript">\n');
		document.write('on error resume next\n');
		document.write('plugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
		document.write('</script>\n');
	}
	
	if (plugin) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" id="HALogo" width="700" height="80">');
		document.write('<param name="movie" value="' + images + '/v2/ha_logo.swf">');
		document.write('<param name="menu" value="false">');
		document.write('<param name="quality" value="high">');
		document.write('<param name="bgcolor" value="#FFFFFF>"');
		document.write('<embed src="' + images + '/v2/ha_logo.swf" menu="false" quality="high" bgcolor="#FFFFFF" swLiveConnect="false" width="700" height="80" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>');
		document.write('</object>');
	
	} else {
		document.write('<img src="' + images + '/v2/ha_logo.png" width="700" height="80" usemap="#HALogo" border="0" alt="Hardware Analysis">');
	}
}

// Adapted from Trac which adapted this from http://www.kryogenix.org/code/browser/searchhi/
function searchHighlight() {
  if (!document.createElement) return;

  var div = document.getElementById("cntBody");   // intelliTxt or cntBody
  if (!div) return;

  function getSearchWords(url) {
    if (url.indexOf('?') == -1) return [];
    var queryString = url.substr(url.indexOf('?') + 1);
    var params = queryString.split('&');
    for (var p in params) {
      var param = params[p].split('=');
      if (param.length < 2) continue;
      if (param[0] == 'q' || param[0] == 'p') { // q= for Google, p= for Yahoo
        var query = decodeURIComponent(param[1].replace(/\+/g, ' '));
        if (query[0] == '!') query = query.slice(1);
        words = query.split(/(".*?")|('.*?')|(\s+)/);
        var words2 = new Array();
        for (var w in words) {
          words[w] = words[w].replace(/^\s+$/, '');
          if (words[w] != '') {
            words2.push(words[w].replace(/^['"]/, '').replace(/['"]$/, ''));
          }
        }
        return words2;
      }
    }
    return [];
  }

  function highlightWord(node, word, searchwordindex) {
    // If this node is a text node and contains the search word, highlight it by
    // surrounding it with a span element
    if (node.nodeType == 3) { // Node.TEXT_NODE
      var pos = node.nodeValue.toLowerCase().indexOf(word.toLowerCase());
      if (pos >= 0 && !/^searchword\d$/.test(node.parentNode.className)) {
        var span = document.createElement("span");
        span.className = "searchword" + (searchwordindex % 5);
        span.appendChild(document.createTextNode(
          node.nodeValue.substr(pos, word.length)));
        node.parentNode.insertBefore(span, node.parentNode.insertBefore(
          document.createTextNode(node.nodeValue.substr(pos + word.length)),
            node.nextSibling));
        node.nodeValue = node.nodeValue.substr(0, pos);
        return true;
      }
    } else if (!node.nodeName.match(/button|select|textarea/i) && node.className != "titlewhite") {
      // Recurse into child nodes
      for (var i = 0; i < node.childNodes.length; i++) {
        if (highlightWord(node.childNodes[i], word, searchwordindex)) i++;
      }
    }
    return false;
  }

  var words = getSearchWords(document.URL);
  if (!words.length) words = getSearchWords(document.referrer);
  if (words.length) {
    for (var w in words) {
      if (words[w].length > 1) highlightWord(div, words[w], w);
    }
  }
}
