// JavaScript Document
var imouseoverlink = new Array();
var imouseoverdiv = new Array();
var passhtml = new Array();
function CatsShow(e){
	if( !e ) e = window.event;
	if (e.target) {
		targ=e.target;
	} else if (e.srcElement) {
		targ=e.srcElement;
	}
	if (targ.nodeType==3) {
		targ = targ.parentNode;
	}
	hoverlink = targ.id;
	showdiv = hoverlink.substr(5);
	pdiv=document.getElementById(showdiv).parentNode;
	while (pdiv.id.length==0){
		pdiv=pdiv.parentNode;
	}
	pdiv=pdiv.id;
	mousex=0;
	mousey=0;
	imouseoverlink[pdiv] = 1;
	imouseoverdiv[pdiv] = 0;
	div=document.getElementById(pdiv);
	if (div.style.display!='block'){
		bdiv=document.getElementById('xo-wrapper');
		if (e.pageX == undefined){
			mousex=e.clientX + document.body.scrollLeft;
			mousey=e.clientY + document.body.scrollTop;
		}else{
			mousex=e.pageX;
			mousey=e.pageY;
		}
		mousex=mousex-bdiv.offsetLeft;
		mousey=mousey-bdiv.offsetTop;
		div.style.top = mousey + 'px';
		div.style.left = mousex + 'px';
		div.style.display='block';
		url = 'http://www.holisticguidance.com/modules/categories/index.php?CatId=' + showdiv ;
		GoAjax(url);
		setTimeout('CheckCatsHide(\''+ pdiv +'\');',300);
	}
}
function CheckCatsHide(DivName){
	if ((imouseoverdiv[DivName] == 0) && (imouseoverlink[DivName] == 0)) {
		document.getElementById(DivName).style.display='none';
	}else{
		setTimeout('CheckCatsHide(\''+ DivName +'\');',300);
	}
}
function CatsHide(pass){
	HideId=pass.id;
	if (HideId.substr(0,4) == 'Show'){
		HideId = HideId.substr(5);
		pdiv=document.getElementById(HideId).parentNode;
		while (pdiv.id.length==0){
			pdiv=pdiv.parentNode;
		}
		HideId=pdiv.id;
		imouseoverlink[HideId] = 0;
	}else{
		imouseoverdiv[HideId] = 0;
	}
}
function SetCatsDiv(pass){
	imouseoverdiv[pass.id] = 1;
}
function GoAjax(url) {
	
	var xmlHttp = null;
	try {
		xmlHttp=new XMLHttpRequest();
	}catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e) {
			  alert("Your browser does not support AJAX!");
			  return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function (){ state_Change (xmlHttp) };
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function PostAjax(url,params) {
	var xmlHttp = null;
	try {
		xmlHttp=new XMLHttpRequest();
	}catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e) {
			  alert("Your browser does not support AJAX!");
			  return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function (){ state_Change (xmlHttp) };
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}
function state_Change(xmlHttp){
	if (xmlHttp.readyState==4) {
		if (xmlHttp.status==200) {
			var mode =  xmlHttp.getResponseHeader('mode');
			if (xmlHttp.getResponseHeader('data')) {
				var data =  xmlHttp.getResponseHeader('data');
				var obj =  xmlHttp.getResponseHeader('obj');
				passhtml[mode]=new Array();
				/*alert(xmlHttp.responseText);
				alert(mode);
				alert(data);*/
				passhtml[mode][data]=xmlHttp.responseText;
				eval (mode + "('" + obj + "','" + data + "')");
			} else {
				eval (mode + "()");
			}
		}
	}
}
function ShowChildCats(obj,pass){
	if (typeof(obj) == 'object') {
		if (obj.innerHTML=="+") {
			set = obj.name;
			url = 'http://www.holisticguidance.com/modules/categories/index.php?CatId=' + pass +'&set='+ set + '&x='  + Math.random();
			GoAjax(url);
			obj.innerHTML = '&nbsp;-';
		} else {
			document.getElementById(pass).style.display = 'none';
			obj.innerHTML = '+';	
		}
	}else{
		if (document.getElementById(pass)){
			document.getElementById(pass).style.display = 'block';
			if (document.getElementById(pass).innerHTML == '') {
				document.getElementById(pass).innerHTML = passhtml['ShowChildCats'][pass];
				delete passhtml['ShowChildCats'][pass];
			}
		}
	}
}
function SaveCats(saveid){
	document.getElementById(saveid);
	objChecks = document.getElementsByName('Cats');
	selcats=[];
	for (i=0;i<objChecks.length;i++){
		if (objChecks[i].checked == true) {
			selcats.push(objChecks[i].value);
			objChecks[i].disabled=true;
		}
	}
	document.getElementById(saveid).value = selcats.join('.');
}
function ClearCats(){
	var objChecks = document.getElementsByName('Cats');
	for (i=0;i<objChecks.length;i++){
		document.getElementsByName('Cats')[i].checked = false;
	}
}