function splashCapsuleVideoPopup(videoTitle,videoHTML)
{
	/*
	var html = "";

	html += "<h2 style='margin-top:0px;margin-bottom:6px;'>";
	html += title;
	html += "</h2>";

	html += "<embed ";
	html += "src='actions/brico_wiki/mediaplayer/player.swf' ";
	html += "width='318' ";
	html += "height='200' ";
	html += "allowscriptaccess='always' ";
	html += "allowfullscreen='true' ";
	html += "flashvars='file=" + videodir + "&autostart=true&fullscreen=true'";
	html += "/>";
	*/
	
	videoHTML = unescape(videoHTML);
	
	videoHTML = "<h2 style='margin-top:0px;margin-bottom:6px;'>"
	          + videoTitle
	          + "</h2>"
	          + videoHTML;
	
	videoHTML += "<img src='pics/close.png' "
	          +  "style='position:absolute;top:-5px;left:285px;cursor:pointer' "
	          +  "onclick='closeCapsuleVideoPopup();'>";
	
	document.getElementById('capsuleVideoPopup').innerHTML = videoHTML;
	document.getElementById('capsuleVideoPopup').style.visibility = 'visible';
}

function closeCapsuleVideoPopup()
{
	document.getElementById('capsuleVideoPopup').innerHTML = '';
	document.getElementById('capsuleVideoPopup').style.visibility = 'hidden';
}

function showSchoolDetailPanel(aLink)
{
	openPopup(unescape(aLink),760,600);
}

function savePageAsPDF(aURL)
{
	var authorId = '1A71736E-FAC0-4EC9-A211-A17F849DDDCA';
	var pageOrientation = '0';
	var topMargin = '0.2';
	var bottomMargin = '0.2';
	var leftMargin = '0';
	var rightMargin = '0';
	var sUriRequest = '';

	sUriRequest = 'author_id=' + authorId;
	sUriRequest += '&page=' + pageOrientation;
	sUriRequest += '&top=' + topMargin;
	sUriRequest += '&bottom=' + bottomMargin;
	sUriRequest += '&left=' + leftMargin;
	sUriRequest += '&right=' + rightMargin;

	//var pURL = 'http://savepageaspdf.pdfonline.com/pdfonline/pdfonline.asp?cURL=' + escape(aURL) + '&' + sUriRequest;
	var pURL = "http://pdfmyurl.com?url="
	         + escape(aURL)
	         + "&-O=Portrait"
	         + "&-s=A4";
	
	window.open(pURL, 'PDFOnline', 'scrollbars=yes,resizable=yes,width=640,height=480,menubar,toolbar,location');
}


// sets a hidden action and item field.
// used to save form changes automatically, when doing other things.
function setActionAndItem(action,item)
{
	document.getElementById('saveactionfield').value='saveandstay';
	document.getElementById('actionContainer').value=action;
	document.getElementById('itemContainer').value=item;
	return true;
}

// check/uncheck a checkbox
function virtualCheckboxClick(aId)
{
	var aBox = document.getElementById(aId); 
	switch(aBox.checked)
	{
		case true: aBox.checked = false; break;
		case false: aBox.checked = true; break;
	}
}

function calculatePopupCentering(xSize,ySize)
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var x = (w-xSize)/2;
	var y  = (h-ySize)/2;
	if (x < 0) {x = 0};
	if (y < 0) {y = 0};
	
	return Array(x,y,w,h);	
}

// open a popup window
function openPopup(aHref,xSize,ySize)
{
	aBuffer = calculatePopupCentering(xSize,ySize);
	var x = aBuffer[0];
	var y = aBuffer[1];
	var w = aBuffer[2];
	var h = aBuffer[3];
	
	/*
	var w = screen.availWidth;
	var h = screen.availHeight;
	var x = (w-xSize)/2;
	var y  = (h-ySize)/2;
	if (x < 0) {x = 0};
	if (y < 0) {y = 0};
	*/
		
	var fenster = window.open(aHref,'webenergie','width=' + xSize + ',height=' + ySize + ',left=' + x + ',top=' + y + ',scrollbars=yes,status=no,location=no,dependent=yes,toolbar=no');
	fenster.focus();
}

// get pictures

function getImage(aPath,aText,form,field,xSize,ySize)
{
	aBuffer = calculatePopupCentering(xSize,ySize);
	var x = aBuffer[0];
	var y = aBuffer[1];
	var w = aBuffer[2];
	var h = aBuffer[3];
	
	var options = 'width=' + xSize + ',height=' + ySize + ',left=' + x + ',top=' + y + ',scrollbars=yes,status=no,location=no,dependent=yes,toolbar=no';
	var opPath  = aPath + "?form=" + form + "&field=" + field; 

	//options = 'width=' + xSize + ',height=' + ySize + ',scrollbars=1'
	win = window.open(opPath,
	                  aText,
	                  options);
	win.focus();
}

function pickImage(aImage,form,field)
{
	window.opener.document.forms[form].elements[field].value = aImage;
	window.opener.document.forms[form].submit();
	window.close();
}

var avatarSubmit,avatarBasePath;
function getAvatars(doSubmit,homePath)
{
   avatarBasePath = homePath;
   if (doSubmit == 1)
   {
      avatarSubmit = true;
   }
   else
   {
      avatarSubmit = false;
   }
   win = window.open(homePath+"forum/avatar/avatars.php",
                     "choisir",
                     "width=600,height=600,scrollbars=1");
   win.focus();
}

function pickAvatar(aPic)
{
   window.opener.document.forms["energyform"].elements["image"].value = aPic;
   window.opener.document.getElementById("avatarpic").src = window.opener.avatarBasePath + "forum/avatar/" + aPic;
   
   if (window.opener.avatarSubmit == true)
   {
      window.opener.document.forms["energyform"].submit();
   }
   window.close();
}

// some print functions

function printStat(catID,sheetID,groupID)
{
   $aString = "printStat.php?catID=" + catID + "&sheetID=" + sheetID + "&groupID=" +groupID;
   win = window.open($aString,"print","width=680,height=600,scrollbars=yes");
   win.focus();
   win.print();
}

function printComp(aGroupID,bGroupID)
{
   $aString = "printComp.php?aGroupID=" +aGroupID + "&bGroupID=" + bGroupID;
   win = window.open($aString,"print","width=680,height=600,scrollbars=yes");
   win.focus();
   win.print();
}

function printReport(item)
{
   $aString = "printReport.php?item=" + item;
   win = window.open($aString,"print","width=680,height=600,scrollbars=yes");
   win.focus();
   win.print();
}


function switchIt(aName,aHref)
{
   document.images[aName].src = aHref;
}

function preloadIt(aHref)
{
	var aPic = new Image(); 
	aPic.src = aHref;
}

function changeCrazyDropDown(anchor)
{
   document.forms["messages"].action += "#"+anchor;
   document.forms["messages"].submit();
}

function getFolder(i)
{
	window.location.href = "formoverview.php?newfolder=" + i;
}

var sure = 0;

function beeingUnsure()
{
   sure = 0;
}

function demanderAvant(aHref,aMessage)
{
   if (confirm(aMessage))
   {
      window.location.href = aHref;
   }
}

function askBefore(aMessage)
{
   if (sure == 0)
   {
      if (confirm(aMessage))
      {
         document.forms["energyForm"].submit();
      }
   }
}

function beeingSure()
{
   sure = 1;
}

function openUserQuest($aNum)
{
   $aString = "userQuest.php";
   win = window.open($aString,"faq","width=400,height=600,scrollbars=yes");
   win.focus();
}

function openFAQ($aNum)
{
   $aString = "faq.php?formID=" + $aNum;
   win = window.open($aString,"faq","width=400,height=600,scrollbars=yes");
   win.focus();
}

function refreshForm(aHref)
{
   beeingSure();
   document.forms["energyForm"].action = aHref;
   document.forms["energyForm"].submit();
}

/* Dropdown menu and navigation related functions. */

var iMax=0;
var aTimer;
var bTimer;
var cTimer;

var iLast=0;
var jLast=0;
var kLast=0;

/* Dropdown menu related functions. */

function ddMenuSetIMax(i)
{
	kMax = i;
	ddMenuHideAll();
}

function ddMenuHideAll()
{
   window.clearInterval(cTimer);
   for (i=0;i<kMax;i++)
   {
      document.getElementById("ddimp" + i).style.visibility = "visible";
      document.getElementById("ddexp" + i).style.visibility = "hidden";
   }
}

function ddMenuExpand(i)
{
   ddMenuHideAll();
   document.getElementById("ddimp" + i).style.visibility = "hidden";
   document.getElementById("ddexp" + i).style.visibility = "visible";
}

function ddMenuImplode(i)
{
   document.getElementById("ddimp" + i).style.visibility = "visible";
   document.getElementById("ddexp" + i).style.visibility = "hidden";
   window.clearInterval(cTimer);
}

function ddMenuHideTimed(i)
{
  window.clearInterval(cTimer);
  kLast = i;
  cTimer = window.setInterval("ddMenuImplode('"+i+"')",500);
}

function ddMenuIsIntern(i)
{
   if (kLast == i)
   {
      window.clearInterval(cTimer);
   }
}


function limitDivHeightByTd(aName)
{
  var maxElems = 12;
  var numOfElems = document.getElementById(aName).getElementsByTagName("td").length;
  if (numOfElems > maxElems)
  {
    document.getElementById(aName).style.height = 6 + maxElems*18;
  }
}

function ddColorize(i)
{
   document.getElementById("ddEntry" + i).style.backgroundColor = "#B7E5F6";
}

function ddUncolorize(i)
{
   document.getElementById("ddEntry" + i).style.backgroundColor = "transparent";
}

/* Navigation related functions. */

function setIMax(i,j)
{
   iMax = i;
   jMax = j;
   hideAll();
}

function colorize(i)
{
   document.getElementById("entry" + i).style.backgroundColor = "#7E9CCB";
}

function uncolorize(i)
{
   document.getElementById("entry" + i).style.backgroundColor = "transparent";
}

function expand(i)
{
   hideAll();
   document.getElementById("imp" + i).style.backgroundColor = "#7E9CCB";
   document.getElementById("exp" + i).style.visibility = "visible";
}

function justExpand(i)
{
   secondHideAll();
   document.getElementById("exp" + i).style.visibility = "visible";
}

function justColorize(i)
{
   hideAll();
   document.getElementById("imp" + i).style.backgroundColor = "#7E9CCB";
}

function justUncolorize(i)
{
   document.getElementById("imp" + i).style.backgroundColor = "transparent";
}

function implode(i)
{
   document.getElementById("imp" + i).style.backgroundColor = "transparent";
   document.getElementById("exp" + i).style.visibility = "hidden";
   window.clearInterval(aTimer);
}

function secondImplode(i)
{
   document.getElementById("imp" + i).style.backgroundColor = "transparent";
   document.getElementById("exp" + i).style.visibility = "hidden";
   window.clearInterval(bTimer);
}

function isIntern(i)
{
   if (iLast == i)
   {
      window.clearInterval(aTimer);
   }
}

function secondIsIntern(i)
{
   if (jLast == i)
   {
      window.clearInterval(bTimer);
   }
}

function hideAll()
{
   window.clearInterval(aTimer);
   for (i=0;i<=iMax;i++)
   {
      document.getElementById("imp" + i).style.backgroundColor = "transparent";
      document.getElementById("exp" + i).style.visibility = "hidden";
   }
}

function hideTimed(i)
{
  window.clearInterval(aTimer);
  iLast = i;
  aTimer = window.setInterval("implode('"+i+"')",500);
}

function secondHideTimed(i)
{
  window.clearInterval(bTimer);
  jLast = i;
  bTimer = window.setInterval("secondImplode('"+i+"')",500);
}

function secondHideAll()
{
   window.clearInterval(aTimer);
   for (j=iMax-jMax;j<=iMax;j++)
   {
      document.getElementById("exp" + j).style.visibility = "hidden";
   }
}

/*End of navigation and dropdown menu functions.*/
