String.prototype.trim = function() {
    val = this;
    if (val) {
        return val.replace(/(^\s*)|(\s*$)/g, "");
    } else {
        return "";
    }
}
String.prototype.contains = function(text) {
    val = this;
    return (val.indexOf(text) > -1);
}
String.prototype.endsWith = function(text) {
    val = this;
    if (!val) return false;
    return val.match(text + '$');
}
function GetXHO() {
	var xmlHttp;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
    		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			xmlHttp = false;
		}
	}
	@end @*/

	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function $(el) {
  return document.getElementById(el);
}

function OI(obj) {
  var msg = Array();
  
  for (p in obj) {
    msg[msg.length] = p;
  }
  msg = msg.join(", ");
  alert(msg);
}
function getX(e) {
  var x = 0;
  while(e) {
    x += e.offsetLeft;
    e = e.offsetParent;
  }
  return x;
}

function OpenWindow(url, height, width, scrollable) {
    if (!height) height = 300;
    if (!width) width = 300;
    scrollable = scrollable ? ",scrollbars" : "";
    var win = window.open(url, "", "resizable=1,toolbar=1,location=0,status=0,menubar=0" + scrollable + ",width=" + width + ",height=" + height);
    win.focus();
}

function ValidateSendToFriend() {
    var fe = $('tbFriendsEmail');
    var fev = fe ? fe.value.trim() : null;
    var ye = $('tbYourEmail');
    var yev = ye ? ye.value.trim() : null;
    
    if (!fev) {
        alert("Please enter your friend's email address.");
        fe.focus();
        return false;
    }
    if (!fev.match("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")) {
        alert("Please verify that your friend's email address is correct.");
        fe.focus();
        return false;
    }
    if (!yev) {
        alert("Please enter your own email address.");
        ye.focus();
        return false;
    }
    if (!yev.match("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")) {
        alert("Please verify that your email address is correct.");
        ye.focus();
        return false;
    }
    return true;
}
function InitSearch() {
    var sb = $("tbSearch");
    
    sb.onfocus = function() {
        if (sb.value.toLowerCase() == "search...") sb.value = "";    
    }
    sb.onblur = function() {
        if (sb.value == "") sb.value = "Search...";
    }
    sb.onkeypress = Search;
}

function Search(e) {
    var d = "/search.aspx?q=";
    var keyCode;
    var source;
    
    if (!e) var e = window.event;
    
    keyCode = e.keyCode ? e.keyCode : e.charCode;
    source = e.srcElement ? e.srcElement : e.target;
    
    if (keyCode == 13) {
        if (source.value.trim() != "") location.href = d + escape(source.value);
        return false;
    }
    
}

function Print() {
    if (noPrintPopup) {
        window.print();
        return;
    }
    var url = location.href;
    if (url.contains("#")) url = url.split("#")[0];
    if (url.indexOf("?") > 0) url += "&print";
    else url += "?print";
    OpenWindow(url, 500, 700, true);
}

function CascadedStyle(el, cssproperty, csspropertyNS){
    if (el.currentStyle) return el.currentStyle[cssproperty];
    else if (window.getComputedStyle) return window.getComputedStyle(el, "").getPropertyValue(csspropertyNS);
 
}
function PrintHandler() {
    if (document.body.className == "print") window.print();
}

/**************************************************/
var drops = new Array();
var aa = null;
var ad = null;
var ht = null;
var o = null;
var bf = null;
var isIE6 = false;
function LoadDrops() {
	var t = $("main-menu");
	o = $("header");
	var a_a = t.getElementsByTagName('a');
	bf = document.createElement('iframe');
	bf.src = 'blank.html';
	bf.style.display = "block";
	bf.style.position = "absolute";
	bf.style.zIndex = "5000";
	isIE6 = navigator.userAgent.indexOf('IE 6') > -1;
	for (var x=1;x<=a_a.length;x++) {
	    var a = a_a[x-1];
	    var d = $("dm" + x);
	    
	    if (!d) a.drop = null;
	    else a.drop = d.id;
	    
        a.onmouseover = function() {
		    var d = $(this.drop);
		    
		    if (ad) {
			    if (ad !== d) {
				    if (ht) window.clearTimeout(ht);
					ad.style.display = "none";
					ad = null;
				} else {
				    if (ht) window.clearTimeout(ht);
			    }
		    }
		    if (aa) {
		        var i = aa.getElementsByTagName("img");
                if (i) {
                    i = i[0];
                    i.src = i.src.replace("-hover.gif", ".gif");
                }
		        aa = null;
		    }
		    
		    var i = this.getElementsByTagName("img");
            if (i && this.className.indexOf('active') == -1) {
                i = i[0];
                i.src = i.src.replace(".gif", "-hover.gif");
            }
            aa = this;
		    
		    if (!d) return;
			var styleProp = "width";
            var width = CascadedStyle(d, "width", "width");
            if (!width) width = "175px";
			width = parseInt(width.replace('px', ''));
			var boundary = o.offsetLeft + o.offsetWidth;
			
			if (this.offsetLeft + width > boundary) {
			    d.style.left = (this.offsetLeft + this.offsetWidth - width - 2) + "px";
			} else {
		        d.style.left = (this.offsetLeft + 2) + "px";
		    }
			var extra = document.all ? 0 : 2;
			var offset = this.offsetParent.offsetTop + this.offsetParent.offsetHeight;

		    d.style.top = offset + "px";
			d.style.display = "block";
			d.style.zIndex = "100000";
		    ad = d;
		    
		    if (isIE6) {
		        bf.style.height = d.offsetHeight + "px";
		        bf.style.top = d.offsetTop + "px";
		        bf.style.left = d.offsetLeft + "px";
		        bf.style.width = d.offsetWidth + "px";
		        bf.style.backgroundColor = "red";
		        bf.style.display = "block";
		        d.parentNode.insertBefore(bf, d.nextSibling);
            }
	    }
		a.onmouseout = function() {
			ht = window.setTimeout("HideDrop()", 250);
	    }
		var over = function() {
		    if (!ht) return;
			window.clearTimeout(ht);
		}
		d.onmouseout = function() {
		    if (ht) window.clearTimeout(ht);
		    ht = window.setTimeout("HideDrop()", 250);
	    }
		d.onmouseover = over;
		var e = d.getElementsByTagName('*');
	    for (var y=0;y<e.length;y++) {
		    e[y].onmouseover = over;
		}
    }
}
function HideDrop() {
    if (aa) {
        var i = aa.getElementsByTagName("img");
        if (i) {
            i = i[0];
            i.src = i.src.replace("-hover.gif", ".gif");
        }
    }
	if (!ad) return;
	ad.style.display = "none";
	if (isIE6) ad.parentNode.removeChild(bf);
	ad = null;
}
/****************************************************/

var _LoadEventFunctions = Array();

function AddLoadEvent(func) {
	_LoadEventFunctions[_LoadEventFunctions.length] = func;	
}
function LoadEvents() {
	for (var x=0;x<_LoadEventFunctions.length;x++) {
		var func = _LoadEventFunctions[x];
		func();	
	}
}

AddLoadEvent(LoadDrops);
AddLoadEvent(PrintHandler);
AddLoadEvent(InitSearch);

window.onload = LoadEvents;
