// By François Verollet
// For VisuHelp
// April 2010

function visuSendData(where, what, place)
{ 
	var req = null; 
	
	if(window.XMLHttpRequest)
		req = new XMLHttpRequest();
	else if (window.ActiveXObject)
		req  = new ActiveXObject(Microsoft.XMLHTTP);
	
	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				visuSay(place, req.responseText);
			}	
			else	
			{
				visuSay(place, "Error: returned status code " + req.status + " " + req.statusText);
			}
			
		} 
	}; 
	req.open("POST", where, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	req.send(what);
}

function visuSay(place, what)
{
	afficher(place);
	document.getElementById(place).innerHTML = what;
	execute();
}

function visuDisplay(what)
{
	document.getElementById(what).style.display = 'inline';
}
function visuDisplayBlock(what)
{
	document.getElementById(what).style.display = 'block';
}


function visuHelp(fa_id)
{
	visuSendData("/visuhelp/receives.php", "fa_id="+fa_id, "visuHelp");
}

function visuHelpListing()
{
	visuSendData("/visuhelp/listing.php", "", "visuHelpListing");
}

var arrow;

function visuHelpHighlightStart()
{
	arrow = document.createElement("img");
	arrow.className = "visuHelpArrow";
	arrow.style.left = "-999px";
	document.getElementById("visuHelp").appendChild(arrow);
}

function visuHelpHighlight(area, mode)
{
	var arrowWidth = 50;
	var arrowHeight = 50;
	
	var thing = document.getElementById(area);
	
	if (mode == "arrow")
	{
		var windowSize = getWindowSize();
		
		arrow.style.top = ( thing.offsetTop - arrowHeight/2 + thing.offsetHeight/2 ) + "px";
		
		if ((thing.offsetLeft / windowSize[0] * 100) < 50)
		{
			arrow.src = "/visuhelp/pictures/arrow_left.png";
			arrow.style.left = ( thing.offsetLeft + thing.offsetWidth ) + "px";
		}else{
			arrow.src = "/visuhelp/pictures/arrow_right.png";
			arrow.style.left = ( thing.offsetLeft - arrowWidth - 10 ) + "px";
		}	
	}
	else if (mode == "blink")
	{
		if (thing.className != "undefined")
		{
			thing.className += " visuHelpHighlight";
		}else{
			thing.className = "visuHelpHighlight";
		}
	}
}

function getWindowSize()
{
  var myWidth = 0, myHeight = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return Array(myWidth, myHeight);
}

function visuHelpScrollTo(area)
{
	var mooToolsIsThere = (typeof MooTools != "undefined") ? true : false;
	
	if (!mooToolsIsThere)
	{
		new Fx.Scroll(window).toElement(area);
	}else{
		//window.location.href = "#"+area;
		window.scrollTo(0, document.getElementById(area).offsetTop - 100);
	}
}

function visuHelpJump(what)
{
	//document.getElementById("visuHelpView").goToFrame(what);
	/*document.getElementById("launcher").GotoFrame(25);
	document.getElementById("launcher").Play();*/
	document.getElementById("launcher").TGotoLabel("/", what);
	document.getElementById("launcher").Play();
}

function visuHelpClose()
{
	visuSendData("/visuhelp/close.php", "", "visuHelp");
}