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 PopupPlayer(url, narrow) {
    if (!narrow) narrow = 575;
    else narrow = 364;
    OpenWindow(url, 303, narrow, false, false)

}
function OpenWindow(url, height, width, scrollable, resizable, name) {
    if (!height) height = 300;
    if (!width) width = 300;
    if (!name) name = "";
    scrollable = scrollable ? ",scrollbars" : "";
    resizable = resizable ? "resizable=1": "resizable=0";
    var win = window.open(url, name, resizable + ",toolbar=0,location=0,status=0,menubar=0" + scrollable + ",width=" + width + ",height=" + height);
    win.focus();
    return win;
}

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 InitHovers() {
    window.setTimeout("SetHovers()", 500);
}
function SetHovers() {
    var img_a = document.getElementsByTagName("img");
    if (!img_a) return;
    for (var x=0;x<img_a.length;x++) {
        var i = img_a[x];
        if (i.src.indexOf("blank.gif") == -1 && i.className.indexOf("hover") != -1) {
            i.onmouseover = function() {
                var arr = this.src.split(".");
                arr[arr.length-2] += "-over"; 
                this.src = arr.join(".");
            }
            i.onmouseout = function() {
                this.src = this.src.replace("-over.", ".");
            }
        }
    }
}

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) {
        location.href = d + escape(source.value);
        return false;
    }
}

function Print() {
    var url = location.href;
    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 ad = null;
var aa = null;
var ht = null;
var o = null;
var fr = null;
function LoadDrops() {
	var t = $("top-menu");
	o = $("outer");
	var j = $("jump");
	/*
	if (navigator.userAgent.indexOf("MSIE 6") > -1) {
    	fr = document.createElement("iframe");
        fr.id = "framer";
        fr.style.position = "absolute";
        fr.frameBorder = 0;
        fr.style.display = "none";
        document.body.insert(fr, document.body.childNodes[0]);
    }
    */
    var mul = t.getElementsByTagName("ul");
    if (mul) mul = mul[0];
    else return;
    var a_a = new Array();
    for (var x=0;x<mul.childNodes.length;x++) {
        var n = mul.childNodes[x];
        if (n.tagName == "LI") {
            var a = n.getElementsByTagName("a");
            if (!a) continue;
            a_a[a_a.length] = a[0];
        }
    }
	var ul_a = t.getElementsByTagName('ul');
	for (var x=a_a.length-1;x>=0;x--) {
	    var a = a_a[x];
	    var ul_a = a.parentNode.getElementsByTagName("ul");
	    var d = null;
	    if (ul_a.length > 0) {
	        ul = ul_a[0];
            var d = ul.parentNode.removeChild(ul);
            d.id = "d" + (x+1);
            if (j) document.body.insertBefore(d, j.nextSibling);
            else document.body.insertBefore(d, document.body.childNodes[0]);
        }
        if (d) a.drop = d.id;
	    a.onmouseover = function() {
		    var d = $(this.drop);
		    if (ad) {
		        if (aa) {
		            aa.className = aa.className.replace("hover", "");
		            aa = null;
		        }
			    if (ad !== d) {
				    if (ht) window.clearTimeout(ht);
				    ad.style.display = "none";
				    if (fr) fr.style.display = "none";
				    ad = null;
			    } else {
				    if (ht) window.clearTimeout(ht);
			    }
		    }
		    if (!d) return;
		    
		    if (this.className.indexOf("active") == -1 && this.className.indexOf("hover") == -1) this.className += " hover";
		    
		    aa = this;
		    
		    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.offsetParent.offsetLeft + width > boundary) {
		        d.style.left = (boundary - width)+ "px";
		    } else {
		        d.style.left = (this.offsetParent.offsetLeft)+ "px";
		    }
		    var extra = document.all ? 0 : 2;
		    var offset = this.offsetParent.offsetTop + this.offsetParent.offsetHeight;
		    
		    d.style.top = offset + "px";
		    d.style.display = "block";
		    
		    ad = d;
		    
		    if (fr) {
    		    fr.style.left = d.offsetLeft + "px";
                fr.style.top = d.offsetTop + "px";
                fr.style.width = d.offsetWidth + "px";
                fr.style.height = d.offsetHeight + "px";
                fr.style.display = "block";
            }		    
	    }
	    a.onmouseout = function() {
	        var d = $(this.drop);
		    if (!d) return;
		    ht = window.setTimeout("HideDrop()", 250);
	    }
	    if (!d) continue;
	    var over = function() {
		    if (!ht) return;
		    window.clearTimeout(ht);
	    }
	    d.onmouseout = function() {
		    if (!ad) return;
		    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 && aa.className.indexOf("hover") > -1) {
	    aa.className = aa.className.replace("hover", "");
	}
	
	if (!ad) return;
	ad.style.display = "none";
	if (fr) fr.style.display = "none";
	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);
AddLoadEvent(InitHovers);

window.onload = LoadEvents;
