function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) {

        for(var i=0; i<document.images.length; i++) {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                i = i-1
            }
        }

        for (i=0; i<document .all.length; i++) {
            var bg = document.all[i].currentStyle.backgroundImage;
            if (bg) {
                if (bg.match(/\.png/i) != null) {
                    var mypng = bg.substring(5,bg.length-2);
                    document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='crop')";
                    document.all[i].style.backgroundImage = "URL('<?php echo SITE_ROOT.'/static/image/x.gif'; ?>')";
                }
            }
        }

    }
}

function zebra(tableId, myColor, start, end)
{
	for (var i=start; i < (document.getElementById(tableId).rows.length - end); i+=2) {
		document.getElementById(tableId).rows[i].style.backgroundColor = myColor;
	}
}

function AddElement(container, type)
{
    var newelement = document.createElement(type);
    container.appendChild(newelement);

    return newelement;
}

function RemoveElement(container, element)
{
    container.removeChild(element);
}

function addAnswer(container)
{
    //~ Increment Counter
    try {
        rowCounter++;
    }
    catch (error) {
        rowCounter = 0
    }
    //~ alert(rowCounter);

    //~ create elements
    var tablebody = document.createElement('tbody');

    var row1 = document.createElement('tr');
    var td11 = document.createElement('td');
    var td12 = document.createElement('td');
    var td13 = document.createElement('td');
    var answerLabel = document.createTextNode('Answer :');
    var emptyText = document.createTextNode('');

    var row2 = document.createElement('tr');
    var td21 = document.createElement('td');
    var td22 = document.createElement('td');
    var td23 = document.createElement('td');
    var textInput = document.createElement('input');
    var checkboxInput = document.createElement('input');
    var checkboxLabel = document.createElement('label');
    var checkboxLabelText = document.createTextNode('Correct Answer');
    var link = document.createElement('a');
    var linkText = document.createTextNode('-');

    //~ set elements attributes
    row1.setAttribute('id', 'row1_' + rowCounter);
    row2.setAttribute('id', 'row2_' + rowCounter);

    textInput.setAttribute('type', 'text');
    textInput.setAttribute('id', 'answerInput_' + rowCounter);
    textInput.setAttribute('name', 'answerInput_' + rowCounter);
    textInput.setAttribute('value', '');
    textInput.setAttribute('size', '80');
    textInput.setAttribute('class', 'textinput');

    checkboxInput.setAttribute('type', 'checkbox');
    checkboxInput.setAttribute('id', 'correctInput_' + rowCounter);
    checkboxInput.setAttribute('name', 'correctInput_' + rowCounter);
    checkboxInput.setAttribute('value', '1');

    checkboxLabel.setAttribute('for', 'correctInput_' + rowCounter);

    link.setAttribute('href', 'javascript:removeAnswer(\'' + rowCounter +'\');');
    link.setAttribute('title', 'Remove Answer');

    //~ make page
    container.appendChild(tablebody);
    tablebody.appendChild(row1);
    row1.appendChild(td11);
    td11.appendChild(emptyText);
    row1.appendChild(td12);
    td12.appendChild(answerLabel);
    row1.appendChild(td13);
    td13.appendChild(emptyText);

    tablebody.appendChild(row2);
    row2.appendChild(td21);
    td21.appendChild(link);
    link.appendChild(linkText);
    td21.appendChild(emptyText);
    row2.appendChild(td22);
    td22.appendChild(textInput);
    row2.appendChild(td23);
    td23.appendChild(checkboxInput);
    td23.appendChild(checkboxLabel);
    checkboxLabel.appendChild(checkboxLabelText);
}

function removeAnswer(id)
{
    var row1 = document.getElementById('row1_' + id);
    var row2 = document.getElementById('row2_' + id);

    container = row1.parentNode;

    container.removeChild(row1);
    container.removeChild(row2);
}

function openConference(url)
{
	window.open(url, 'conference', 'width=800,height=700');
}

function openFinishedConference(url)
{
	window.open(url, 'finished_conference', 'width=800,height=700');
}

function changeColor(element, color)
{
    element.style.background = color;
}

function courseWindowOpen(URL, windowName)
{
	var specs = "channelmode=no"
		+ ",directories=no"
		+ ",fullscreen=no"
		+ ",height=600"
		+ ",left=" + ((screen.availWidth - 800) / 2)
		+ ",location=no"
		+ ",menubar=no"
		+ ",resizable=no"
		+ ",scrollbars=no"
		+ ",status=no"
		+ ",titlebar=no"
		+ ",toolbar=no"
		+ ",top=" + ((screen.availHeight - 600) / 2)
		+ ",width=800";

	var objCourseWindow = window.open (URL, windowName, specs);
	objCourseWindow.focus();
}

function disableChapterSelector(Selector, Destination)
{
	if (true == Selector.checked) {
		Destination.disabled = false;
	} else {
		Destination.disabled = true;
	}
}

function multiplyAnswers(Answers, destination, numberof) {
	
	var container = document.getElementById(destination);
	var table = document.createElement('table');
	table.style.border = '1px solid #f0f0f0';
	table.style.width = '100%';
	table.style.margin = '0 0 10px 0';
	
	var colgroup = document.createElement('colgroup');
	
	var col1 = document.createElement('col');
	col1.setAttribute('width', '30');
	var col2 = document.createElement('col');
	col2.setAttribute('width', '');
	colgroup.appendChild(col1);
	colgroup.appendChild(col2);
	
	table.appendChild(colgroup);
	
	var tr1;
	var tr2;
	var td1;
	var td2;
	var td3;
	var td4;
	var tbody;
	for (i in Answers) {
		tbody = document.createElement('tbody');
		tr1 = document.createElement('tr');
		tr2 = document.createElement('tr');
		td1 = document.createElement('td');
		td2 = document.createElement('td');
		td3 = document.createElement('td');
		td4 = document.createElement('td');
		textempty = document.createTextNode('&nbsp;');
		textlabel = document.createTextNode(Answers[i]);
		td1.innerHTML = '&nbsp;';
		td2.innerHTML = Answers[i];
		td3.innerHTML = '&nbsp;';
		td4.innerHTML = '<input type="text" name="text_answer' + numberof + '_' + i + '" id="answer_' + i + '" value="" size="80" class="textinput"/>';
		tr1.appendChild(td1);
		tr1.appendChild(td2);
		tr2.appendChild(td3);
		tr2.appendChild(td4);
		tbody.appendChild(tr1);
		tbody.appendChild(tr2);
		table.appendChild(tbody);
	}
	
	container.appendChild(table);
	
//	for (i in Answers) {
//		txt += i + " => " + Answers[i] + "\n";
//	}
//	
//	alert(txt);
}

function corectMenu()
{
	var objMenu = document.getElementById('menu').getElementsByTagName('table')[0];
	var objMenuCells = objMenu.getElementsByTagName('td');
	var objMenuHeight = objMenu.clientHeight;
	
	for (var i=0; i < objMenuCells.length; i++) {
		var content;
		
		if (objMenuCells[i].getElementsByTagName('span').length) {
			content = objMenuCells[i].getElementsByTagName('span')[0];
		} else {
			content = objMenuCells[i].getElementsByTagName('a')[0];
		}
		
		var cellHeight = objMenuHeight - 20;
		content.style.height = cellHeight + 'px';
	}
	
}

function openImageWindow(URL)
{
	var specs = "channelmode=no"
		+ ",directories=no"
		+ ",fullscreen=yes"
		+ ",height=" + screen.availHeight
		+ ",left=0"
		+ ",location=no"
		+ ",menubar=no"
		+ ",resizable=no"
		+ ",scrollbars=yes"
		+ ",status=no"
		+ ",titlebar=no"
		+ ",toolbar=no"
		+ ",top=0"
		+ ",width=" + screen.availWidth;

	var objImageWindow = window.open (URL, 'ETImage', specs);
	objImageWindow.focus();
}

//glossary
if (!(document.all?true:false)) document.captureEvents(Event.MOUSEMOVE)

document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0

var openElement = null;

function getMouseXY(e) {
  if (document.all?true:false) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }  
  
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

	if (openElement!=null) displayDiv(openElement);

  return true
}

function displayDiv(moE)
{
	ttempX=tempX;
	ttempY=tempY;
	if (document.body.clientWidth-5<tempX+moE.clientWidth) ttempX=tempX-moE.clientWidth-1;
	if (document.body.clientHeight<tempY+moE.clientHeight) ttempY=tempY-moE.clientHeight-1;
	moE.style.marginLeft=ttempX + 'px';
	moE.style.marginTop=ttempY + 'px';
}

function mouseOver(moElement)
{
	var moE=document.getElementById(moElement);
	document.body.insertBefore(moE, document.body.firstChild)
	moE.style.position='absolute';
	moE.style.zIndex='2000';
	moE.style.display='block';
	displayDiv(moE);
	openElement=moE;
}

function mouseOut(moElement)
{
	document.getElementById(moElement).style.display='none';
	openElement=null;
}

function expandCenter(id)
{
	document.getElementById(id).style.display = "block";
	document.getElementById('colapse_' + id).style.display = "inline";
	document.getElementById('expand_' + id).style.display = "none";
}

function colapseCenter(id)
{
	document.getElementById(id).style.display = "none";
	document.getElementById('colapse_' + id).style.display = "none";
	document.getElementById('expand_' + id).style.display = "inline";
}

function checkRoles()
{
	if (document.getElementById('chkAccessLevel1').checked == true)
	{
		document.getElementById('chkAccessLevel16').checked = true;
		document.getElementById('chkAccessLevel256').checked = true;
		document.getElementById('chkAccessLevel1024').checked = true;
	}
}
