﻿function mh_show(user_id,this_section, d_height) {
	var this_user_id = user_id;
	var section = this_section
	var theElementId = "mh_" + section + "_switch";
	var imageToSwitch = document.getElementById(theElementId);
	imageToSwitch.src = "pics/general/busy.gif";
	imageToSwitch.title = "please wait...";
	var theAnchorId = 'mh_' + section + '_switch_a';
	var anchorToSwitch = document.getElementById(theAnchorId);
	anchorToSwitch.href = "javascript:mh_hide(" + this_user_id + ",'" + section + "','" + d_height + "')";
	var theElementId = 'mh_user_summary_' + section + '_content';
	var elementToShow = document.getElementById(theElementId);
	elementToShow.style.visibility = 'visible';
	elementToShow.style.height = d_height;
	elementToShow.style.display = 'block';
	//check_page_height();
	//if (!xmlhttp) {
	//	xmlhttp = getXmlHttpRequest();
	//}
	//if (!xmlhttp) {
	//	alert("could not create XmlHttpRequest");
	//	return;
	//}
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + this_user_id;
	var url = 'myhome/' + section + '.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				//alert("print");
				var theElementId = 'mh_user_summary_' + section + '_content';
				//alert(theElementId);
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				var theImageId = 'mh_' + section + '_switch'
				var imageToSwitch = document.getElementById(theImageId);
				imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
				imageToSwitch.title = "hide details";
				xi[xhri] = 1;
 				xhr[xhri] = null;
 				check_page_height();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
	if ((section == "no") || (section == "ms") || (section == "gs") || (section == "md")) {
		mh_refresh_head(this_user_id,section);
	}
}

function mh_print() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		//alert("print");
		var theElementId = 'mh_user_summary_' + section + '_content';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = xmlhttp.responseText;
		var theImageId = 'mh_' + section + '_switch'
		var imageToSwitch = document.getElementById(theImageId);
		if (hs == "open") {
			imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
			imageToSwitch.title = "hide details";
		} else {
			imageToSwitch.src = "pics/general/ajaxarrowright.gif";
			imageToSwitch.title = "show details";
		}
		mh_refresh_head(this_user_id,section);
		check_page_height();
	} else {
		try {
			var alertStr = "xmlhttp.readyState=" + xmlhttp.readyState + " xmlhttp.status=" + xmlhttp.status;
		}
		catch (e) {
			var alertStr = "error getting xmlhttp.readyState and xmlhttp.status";
		}
		//alert(alertStr);
	}
}

function mh_hide(user_id,section, d_height) {
	var theElementId = 'mh_user_summary_' + section + '_content';
	var elementToShow = document.getElementById(theElementId);
	elementToShow.style.visibility = 'hidden';
	elementToShow.style.height = '0px';
	//elementToShow.style.border = 'dotted 0 #51818f';
	elementToShow.style.display = 'none';
	elementToShow.innerHTML = "";
	var theImageId = 'mh_' + section + '_switch'
	var imageToSwitch = document.getElementById(theImageId);
	imageToSwitch.src = "pics/general/ajaxarrowright.gif";
	imageToSwitch.title = "show details";
	var theAnchorId = 'mh_' + section + '_switch_a';
	var anchorToSwitch = document.getElementById(theAnchorId);
	anchorToSwitch.href = "javascript:mh_show(" + user_id + ",'" + section + "','" + d_height + "')";
	check_page_height();
	if ((section == "no") || (section == "ms") || (section == "gs") || (section == "md")) {
		mh_refresh_head(user_id,section);
	}
}

function mh_show_static(user_id,this_section) {
	this_user_id = user_id;
	section = this_section
	var theImageId = 'mh_' + section + '_switch'
	var imageToSwitch = document.getElementById(theImageId);
	imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
	imageToSwitch.title = "hide details";
	var theAnchorId = 'mh_' + section + '_switch_a';
	var anchorToSwitch = document.getElementById(theAnchorId);
	anchorToSwitch.href = "javascript:mh_hide_static(" + this_user_id + ",'" + section + "')";
	var theElementId = 'mh_user_summary_' + section + '_content';
	var elementToShow = document.getElementById(theElementId);
	elementToShow.style.visibility = 'visible';
	elementToShow.style.height = 'auto';
	//elementToShow.style.border = 'dotted 1 #51818f';
	elementToShow.style.display = 'block';
	check_page_height();
}

function mh_hide_static(user_id,section) {
	var theElementId = 'mh_user_summary_' + section + '_content';
	var elementToShow = document.getElementById(theElementId);
	elementToShow.style.visibility = 'hidden';
	elementToShow.style.height = '0px';
	//elementToShow.style.border = 'dotted 0 #51818f';
	elementToShow.style.display = 'none';
	var theImageId = 'mh_' + section + '_switch'
	var imageToSwitch = document.getElementById(theImageId);
	imageToSwitch.src = "pics/general/ajaxarrowright.gif";
	imageToSwitch.title = "show details";
	var theAnchorId = 'mh_' + section + '_switch_a';
	var anchorToSwitch = document.getElementById(theAnchorId);
	anchorToSwitch.href = "javascript:mh_show_static(" + this_user_id + ",'" + section + "')";
	check_page_height();
}

function mh_no_x(user_id,this_section,this_note,this_range) {
	//alert("start");
	this_user_id = user_id;
	section = this_section
	if (!xmlhttp) {
		xmlhttp = getXmlHttpRequest();
	}
	if (!xmlhttp) {
		alert("could not create XmlHttpRequest");
		return;
	}
	var theElementId = "mh_" + section + "_switch";
	var imageToSwitch = document.getElementById(theElementId);
	var arrowCurrentSrc = imageToSwitch.src;
	arrowCurrentSrc = arrowCurrentSrc.substr((arrowCurrentSrc.lastIndexOf("/") + 1),arrowCurrentSrc.length)
	imageToSwitch.src = "pics/general/busy.gif";
	imageToSwitch.title = "please wait...";
	if (arrowCurrentSrc == "ajaxarrowdown.gif") {
		//alert("arrow down - " + arrowCurrentSrc);
		hs = "open";
	} else {
		//alert("arrow right - " + arrowCurrentSrc);
		hs = "closed";
		//var theElementId = 'mh_' + section + '_switch'
		//var imageToSwitch = document.getElementById(theElementId);
		//imageToSwitch.src = "pics/general/ajaxarrowright.gif";
		//imageToSwitch.title = "show details";
	}
	var qry = 'js=yes&user_id=' + this_user_id + '&action=clear&note=' + this_note + '&range=' + this_range + '&hs=' + hs;
	var url = 'myhome/' + section + '.php';
	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = mh_print;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(qry);
}

function mh_refresh_head(user_id,this_section) {
	this_user_id = user_id;
	section = this_section;
	if (!xmlhttp2) {
		xmlhttp2 = getXmlHttpRequest();
	}
	if (!xmlhttp2) {
		alert("could not create XmlHttpRequest");
		return;
	}
	var qry = 'js=yes&user_id=' + this_user_id + '&action=refresh_head';
	var url = 'myhome/' + section + '.php';
	xmlhttp2.open('POST', url, true);
	xmlhttp2.onreadystatechange = mh_print_head;
	xmlhttp2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp2.send(qry);
}

function mh_print_head() {
	if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
		//alert("refresh head");
		var theElementId = 'mh_' + section + '_head';
		var elementToShow = document.getElementById(theElementId);
		elementToShow.innerHTML = xmlhttp2.responseText;
	} else {
		try {
			var alertStr = "xmlhttp2.readyState=" + xmlhttp2.readyState + " xmlhttp2.status=" + xmlhttp2.status;
		}
		catch (e) {
			var alertStr = "error getting xmlhttp2.readyState and xmlhttp2.status";
		}
		//alert(alertStr);
	}
}

function mh_sort(user_id,section,order_by,sort_dir) {
	var theElementId = "mh_" + section + "_switch";
	var imageToSwitch = document.getElementById(theElementId);
	imageToSwitch.src = "pics/general/busy.gif";
	imageToSwitch.title = "please wait...";
	var xhri = xhrRequest('html');
	var qry = 'js=yes&user_id=' + user_id + '&order_by=' + order_by + '&sort_dir=' + sort_dir;
	var url = 'myhome/' + section + '.php';
	xhr[xhri].open('POST', url, true);
	xhr[xhri].onreadystatechange = function () {
			if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
				var theElementId = 'mh_user_summary_' + section + '_content';
				var elementToShow = document.getElementById(theElementId);
				elementToShow.innerHTML = xhr[xhri].responseText;
				var theImageId = 'mh_' + section + '_switch'
				var imageToSwitch = document.getElementById(theImageId);
				imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
				imageToSwitch.title = "hide details";
				xi[xhri] = 1;
 				xhr[xhri] = null;
 				check_page_height();
			} else {
				try {
					var alertStr = "xhr[xhri].readyState=" + xhr[xhri].readyState + " xhr[xhri].status=" + xhr[xhri].status;
				}
				catch (e) {
					var alertStr = "error getting xhr[xhri].readyState and xhr[xhri].status";
				}
				//alert(alertStr);
			}
		};
	xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xhr[xhri].send(qry);
}

function mh_toggle_medalgdetail(list_id) {
	var theElementId = 'md_given_list_' + list_id;
	var elementToShow = document.getElementById(theElementId);
	if (elementToShow.style.visibility == 'hidden') {
		elementToShow.style.visibility = 'visible';
		elementToShow.style.height = 'auto';
		elementToShow.style.display = 'block';
	} else {
		elementToShow.style.visibility = 'hidden';
		elementToShow.style.height = '0px';
		elementToShow.style.display = 'none';
	}
	var theImageId = 'mh_mdl_' + list_id + '_switch'
	var imageToSwitch = document.getElementById(theImageId);
	//alert(imageToSwitch.src.substring(imageToSwitch.src.lastIndexOf("/")));
	if (imageToSwitch.src.substring((imageToSwitch.src.lastIndexOf("/"))+1) == "ajaxarrowright.gif") {
		imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
		imageToSwitch.title = "hide details";
		imageToSwitch.alt = "hide details";
	} else {
		imageToSwitch.src = "pics/general/ajaxarrowright.gif";
		imageToSwitch.title = "show details";
		imageToSwitch.alt = "show details";
	}
	//var theAnchorId = 'mh_mdl_' + list_id + '_switch_a';
	//var anchorToSwitch = document.getElementById(theAnchorId);
	//anchorToSwitch.href = "javascript:mh_show_static(" + this_user_id + ",'" + section + "')";
	check_page_height();
}

function mh_toggle_me2gdetail(list_id) {
	var theElementId = 'me2_given_list_' + list_id;
	var elementToShow = document.getElementById(theElementId);
	if (elementToShow.style.visibility == 'hidden') {
		elementToShow.style.visibility = 'visible';
		elementToShow.style.height = 'auto';
		elementToShow.style.display = 'block';
	} else {
		elementToShow.style.visibility = 'hidden';
		elementToShow.style.height = '0px';
		elementToShow.style.display = 'none';
	}
	var theImageId = 'mh_me2_' + list_id + '_switch'
	var imageToSwitch = document.getElementById(theImageId);
	//alert(imageToSwitch.src.substring(imageToSwitch.src.lastIndexOf("/")));
	if (imageToSwitch.src.substring((imageToSwitch.src.lastIndexOf("/"))+1) == "ajaxarrowright.gif") {
		imageToSwitch.src = "pics/general/ajaxarrowdown.gif";
		imageToSwitch.title = "hide details";
		imageToSwitch.alt = "hide details";
	} else {
		imageToSwitch.src = "pics/general/ajaxarrowright.gif";
		imageToSwitch.title = "show details";
		imageToSwitch.alt = "show details";
	}
	//var theAnchorId = 'mh_mdl_' + list_id + '_switch_a';
	//var anchorToSwitch = document.getElementById(theAnchorId);
	//anchorToSwitch.href = "javascript:mh_show_static(" + this_user_id + ",'" + section + "')";
	check_page_height();
}

