var req;
var targetlb;
var targettb;
var targetform;
var targetContainer;
addLoadEvent(collapseMenu);
addLoadEvent(prepareMenu);
// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.
var HOST = 'www.mojomark.com';
function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mojoname', f.p_author_name.value, now, '', HOST, '');
    setCookie('mojomail', f.p_author_email_address.value, now, '', HOST, '');
    setCookie('mojourl', f.p_author_href.value, now, '', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mojoname', '', HOST);
    deleteCookie('mojomail', '', HOST);
    deleteCookie('mojourl', '', HOST);
    f.p_author_name.value = '';
    f.p_author_email_address.value = '';
    f.p_author_href.value = '';
}
function crumbValue (inValue) {
    document.getElementById('breadcrumb').innerHTML = inValue;
}
function showID(itemId) {
   document.getElementById(itemId).style.display = tr_display;
}
function hideID (itemId) {
   document.getElementById(itemId).style.display = 'none';
}
function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}
function getMoreHtml () {
    if ((req.readyState == 4) && (req.status == 200)) {
        document.getElementById(targetContainer).innerHTML = req.responseText;
	document.getElementById("divProgress").style.display = 'none';
    }
    else {
	document.getElementById("divProgress").style.display = 'block';
    }
}
function loadNewContent(url) {
    req=getXMLHTTP();
	if(req){
        req.onreadystatechange = getMoreHtml;
        req.open("GET", url, true);
        req.send(null);
	}
}
function loadInto(url,containerID) {
	targetContainer = containerID;
	loadNewContent(url );
} 
function showMore(varA1, varB1){
var123 = ('varXYZ' + (varA1));
varABC = ('varP' + (varA1));
if( document.getElementById ) {
if( document.getElementById(var123).style.display ) {
if( varB1 != 0 ) {
document.getElementById(var123).style.display = "block";
document.getElementById(varABC).style.display = "none";
} else { document.getElementById(var123).style.display = "none"; 
document.getElementById(varABC).style.display = "block"; }
} else { location.href = varB1;
return true; }
} else { location.href = varB1;
return true; }
}
function open_new_window (the_url,win_name,win_props) {
        window.open(the_url,win_name,win_props); 
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function collapseMenu(node) {
	if (!document.getElementById) return false;
	if (!document.getElementById("menu")) return false;
	if (!node) node = document.getElementById("menu");

	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
			var child = node.childNodes[i];
			if (child.nodeName == "UL") {
					child.style.display = "none";
			}
			collapseMenu(child);
		}		
	}

}

function prepareMenu() {
	if (!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById("menu")) return false;

	var links = document.getElementById("menu").getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {		
		links[i].onclick = function() {
			toggleMenu(this.parentNode.getElementsByTagName("UL")[0], this.href);
			return false;
		}
	}
}

function toggleMenu(node, link) {
	if (!document.getElementById) return false;
	if (!link) return false;
	if (!node) location.href = link.href;

	// Collapse all nodes, and only show clicked node (when clicking top level of menu)
	if (node.parentNode.parentNode.id == "menu") {
		hideTopLevels();
	}
	
	if (node.style.display == "") {
		node.style.display = "none"
	} else {
		node.style.display = ""
	}
}

function hideTopLevels() {
	if (!document.getElementById) return false;
	if (!(node = document.getElementById("menu"))) return false;	
	
	if (node.childNodes.length > 0) {
		for (var i=0; i<node.childNodes.length; i++) {
			var child = node.childNodes[i];
			for(var j=0; j<child.childNodes.length; j++) {
				var grandchild = child.childNodes[j];
				if (grandchild.nodeName == "UL") {
					if (grandchild.style.display == '') {
						grandchild.style.display = "none";
					}
				}
			}
		}		
	}
}
