// JavaScript Document

// display profile and image
function showProfile(uid, img){

	it_img = document.getElementById('imgdisplayn')
	it_img.innerHTML = '<img src="showimg.php?img='+img+'">'
	
	// now get the member profile
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url= "profileload.php?id="+uid
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)		
}

function stateChanged() 
{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("mem_info").innerHTML=xmlHttp.responseText 
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


// Show Hide Images
function showImage($img){
	
	$it1 = document.getElementById('imgdisplay');
	
	$it1.innerHTML = '<img src="img.php?img='+$img+'">';
	
	$it1.style.display = 'block';
	
	
}

function hideImage(){
	
	$it1 = document.getElementById('imgdisplay');
	
	$it1.innerHTML = '';
	
	$it1.style.display = '';
	
	
}

function showOption(){
	
	document.getElementById('howlong1').style.display = 'block';
	document.getElementById('howlong2').style.display = 'block';
	
}

function hideOption(){
	
	document.getElementById('howlong1').style.display = 'none';
	document.getElementById('howlong2').style.display = 'none';
	
}

// Show submenu
var over = 0;
function showsub(elID, lin){
	document.getElementById(elID).style.display = "";
	document.getElementById(elID).style.left = getX(lin) - 0 + 'px'; //change the number for left positioning
	document.getElementById(elID).style.top = getY(lin) + 27 + 'px';
	//alert(getX(lin)+', '+window.event.clientX);
}

function hidesub(elID){
	var t=setTimeout("closesub('"+elID+"')",50);
}

function closesub(elID){
	if(over == 0){
		document.getElementById(elID).style.display = "none";
	}
}

function subshow(elID){
	over = 1;
	document.getElementById(elID).style.display = "";
}

function subhide(elID){
	over = 0;
	document.getElementById(elID).style.display = "none";
}
//

//Show and Hide Tooltip

var xpos;
var ypos;
function afptooltip_show(tooltipId, eId)
{
	it = document.getElementById(tooltipId);
    it.style.display = "block";
		if(xpos){
			mousex = xpos;
			mousey = ypos;			
			// Compare bottom of menu to bottom of window
			abspopupbottomF = mousey + it.clientHeight + 10;
			abswindowbottomF = GetAbsWindowBottom();
			// If menu goes below bottom of window, move it up!
			if (abspopupbottomF > abswindowbottomF)
				mousey = mousey - (abspopupbottomF - abswindowbottomF);
		}else{
		  mousex = window.event.clientX+document.body.scrollLeft+10;
		  mousey = window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			// Compare bottom of menu to bottom of window
			abspopupbottomI = mousey + it.clientHeight + 10;
			abswindowbottomI = GetAbsWindowBottom();
			// If menu goes below bottom of window, move it up!
			if (abspopupbottomI > abswindowbottomI)
				mousey = mousey - (abspopupbottomI - abswindowbottomI);
		}

	if(eId){
		// Compare bottom of menu to bottom of window
		abspopupbottom = getY(eId) + it.clientHeight + 56;
		abswindowbottom = GetAbsWindowBottom();
		
		// If menu goes below bottom of window, move it up!
		if (abspopupbottom > abswindowbottom){
			//newY = getY(eId) - (abspopupbottom - abswindowbottom);
			it.style.left = getX(eId) + 57 + 'px';
			it.style.top = getY(eId) - it.clientHeight - 8 + 'px';
		}else{
			it.style.left = getX(eId) + 57 + 'px';
			it.style.top = getY(eId) + 62 + 'px';
		}
			
		
	}else{
		it.style.top = mousey+'px';
		it.style.left = mousex+20+'px'; 
	}//else
}

function afptooltip_hide(id)
{
    it = document.getElementById(id); 
    it.style.display = "none"; 
}
if(navigator.appName!="Microsoft Internet Explorer"){
	document.onmousemove = function(evt){
		xpos = evt.pageX;
		ypos = evt.pageY;
	}
}

//find  X and Y of element
function getY(oElement)
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function getX(oElement)
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function GetAbsWindowBottom()
{
    // Compute the bottom of the popup window and the bottom of
    // the browser window, in absolute co-ordinates - different
    // on all browsers but the below should be accurate usually!
 
    var abswindowbottom = 0;
    if (typeof(window.innerHeight) == 'number')
        abswindowbottom = window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        abswindowbottom = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight)
        abswindowbottom = document.body.clientHeight;
 
    if (typeof(window.pageYOffset) == 'number')
        abswindowbottom = abswindowbottom + window.pageYOffset;
    else if (document.body && document.body.scrollTop)
        abswindowbottom = abswindowbottom + document.body.scrollTop;
    else if (document.documentElement && document.documentElement.scrollTop)
        abswindowbottom = abswindowbottom + document.documentElement.scrollTop;
    return abswindowbottom;
}