// JavaScript Document

function browserHeight(){
  bHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    bHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'    
    bHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    bHeight = document.body.clientHeight;
  }
  return bHeight;
}

function browserWidth(){
  bWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    bWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'    
    bWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    bWidth = document.body.clientWidth;
  }
  return bWidth;
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function showOverlay(boxWidth,boxHeight){
	if(boxWidth == null){
		boxWidth = '300';
	}
	if(boxHeight == null){
		boxHeight = '100';
	}
	try{		
		var over = document.getElementById('over');
		over.style.width = '100%';
		//over.style.height = document.body.clientHeight + 'px';


		
		var box = document.getElementById('box');
		box.style.display = 'inline';
		box.style.visibility = 'visible';	
		box.style.width = boxWidth + 'px';
		box.style.height = boxHeight + 'px';		
		//center the box
		var divtop = (browserHeight() /2) - (boxHeight / 2);
		if(divtop < 10){
			divtop = 10;
		}
		
		box.style.top = divtop + 'px';
		box.style.left = (document.body.clientWidth / 2) - (boxWidth /2) + 'px'
		setOpacity(box,100);
		
		 if(window.scrollMaxY > browserHeight()){
			  var bHeight = window.scrollMaxY + browserHeight();
		  }else{
			  var bHeight = browserHeight();
		  }
		over.style.height = bHeight + 'px';
		over.style.display = 'block';
		over.style.visibility = 'visible';	
		//setOpacity(over,0);
		//fadeIn('over',0);
		setOpacity(over,60);		
	}
	catch(e){
//		alert(e);
	}
}

function hideOverlay(){
	try{
		var over = document.getElementById('over');
		var box = document.getElementById('box');
		var graph = document.getElementById('graph_1year');		
		setOpacity(over,0);
		setOpacity(box,0);
		//setOpacity(graph,0);
		//fadeOut('over',100);
		box.style.border = '4px solid #ff3300';
		window.setTimeout('hideOverlayTimeout()',100);
	}
	catch(e){
//		alert(e);
	}
}

function hideOverlayTimeout(){
	var over = document.getElementById('over');
	over.style.display = 'none';
	over.style.visibility = 'hidden';
	var box = document.getElementById('box');
	box.style.display = 'none';
	box.style.visibility = 'hidden';	
	try{
		var graph = document.getElementById('graph_1year');
		graph.style.visibility = 'hidden';
		graph.style.display = 'none';
	}
	catch(e){
		//
	}
}

//user stats
var xmlHttp;
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;
}

function getCalendar(){
	document.getElementById("box").style.cursor = "wait";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="includes/training/calendar.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	//document.getElementById("graph_1year").style.background-image = "url(../includes/user/stats/images/graph_1year.jpg)";
	document.getElementById("modal_calendar").innerHTML=xmlHttp.responseText;
	document.getElementById("box").style.cursor = "default";

	}
	else{
		document.getElementById("modal_calendar").innerHTML= "<center>Loading Calender</center>";
	}
}
	
function trainCalendar(){
	var height = 307;
	
	var box = document.getElementById('box');
	box.style.border = '1px solid #000000';
	box.innerHTML = '<div id="modal_calendar" class="graphs"></div>';
	
	var modal_calendar = document.getElementById('modal_calendar');
	modal_calendar.style.visibility = 'visible';
	modal_calendar.style.display = 'block';
	
	setOpacity(modal_calendar,100);
	getCalendar();
	showOverlay(438,height);	
}