// These variables are for saving the original background colors
var previousElements=new Array();
var previousColors=new Array();
var highlightColor='#ecd6ff';

function highlightTableRow(tableRow)
{
  var i=0;
  // Restore color of the previously highlighted row
  for (i; i<previousElements.length; i++)
  {
    var myElement=previousElements[i];
    // hack!!! code to support Netscape 6 and 7
    if (previousColors[i]==0)
    {
      if (myElement.style)
      {
        myElement.style.background=0;
      }
    }
    // end hack
    else
    {
      myElement.style["backgroundColor"]=previousColors[i];
    }
    previousElements[i]=previousColors[i]=0;
  }

  // Highlight every cell on the row
  if (tableRow)
  {
    // The first child will be (or should be) a <TD>
    var tableCell=tableRow.firstChild;
    while (tableCell && tableCell.tagName!="TD")
    {
      tableCell=tableCell.nextSibling;
    }

    var i=0;
    // Loop through every sibling (a sibling of a cell should be a cell)
    // We then highlight every siblings
    while (tableCell)
    {
      // Make sure it's actually a cell (a TD)
      if (tableCell.tagName=="TD")
      {
        previousElements[i]=tableCell;
        // If no style has been assigned, assign it, otherwise Netscape will 
        // behave weird.
        if (!tableCell.style)
        {
          tableCell.style={};
        }
        else
        {
          // If, row color already defined, save it so we can restore the color
          // when the cursor is no longer over the row
          if (tableCell.parentNode.style["backgroundColor"])
          {
            previousColors[i]=tableCell.parentNode.style["backgroundColor"];
          }
          else
            previousColors[i]=tableCell.style["backgroundColor"];

        }
        // Assign the highlight color
        tableCell.style["backgroundColor"]=highlightColor;

        // Optional: alter cursor
        tableCell.style.cursor='default';
        i++;
      }
      // Go to the next cell in the row
      tableCell=tableCell.nextSibling;
    }
    tableRow.onMouseOut="highlightTableRow(0);";
  }
}


function a_href(url)
{
	document.location = url;	
}

function swap_content( tr ) {
	displayType = ( document.getElementById( tr ).style.display == 'none' ) ? 'block' : 'none';
	document.getElementById( tr ).style.display = displayType;
}

function swap_multi_content( tr ) {
	alldivs = document.getElementsByTagName('tr');
	for(i = 0; i < alldivs.length; i++) {
		if(alldivs[i].id == tr)
		{
			displayType = ( alldivs[i].style.display == 'none' ) ? 'block' : 'none';
			alldivs[i].style.display = displayType;
		}
	}
}

function check_select(select, button)
{
	if(select.value != 0)
	{
		button.disabled = false;
		button.value = 'Submit';
	}
	else
	{
		button.disabled = true;
		button.value = 'Select doc first...';
	}
}

function toggleenable(element, check)
{
	if(element.disabled)
	{
		if(confirm("Setting a custom revision number may harm the consistency of the document. Please proceed only if you know what you are about to do! Proceed?"))
		{
			check.checked = true;
			element.disabled = false;
		}
		else
		{
			check.checked = false;
			element.disabled = true;
		}
	}
	else
	{
		check.checked = false;
		element.disabled = true;
	}
}

function toggle(element, img)
{
	// Lokale Variable definieren
	var displayStyle, obj;

	// Standard-Darstellungsart
	displayType="";
	
	// ID gefunden: Kurzform fuer Element-Objekt definieren
	obj=document.getElementById(element);
	
	// Aktionsstyle und Ausnahmestyle festlegen
	if(obj.style.display == 'none')	//Ausklappen
	{
		displayStyle=displayType;
		displayXStyle="none";
		if(img!=null)
			document.images[img].src = 'gfx/u.gif';
	}
	else							//Einklappen
	{
		displayStyle="none";
		displayXStyle=displayType;
		if(img!=null)
			document.images[img].src = 'gfx/d.gif';
	}

	// Display-Style setzen
	obj.style.display=displayStyle;
}

function jumpselect(id, element)
{
	var found = false;
	if(id)
	{
		for (i=0; i<element.length; i++)
		{
			if(element.options[i].value==id)
			{
				element.options[i].selected = true;
				found = true;
				break;
			}
		}
	}

	if(found)
	{
		element.style.backgroundColor = '#ffffff';
	}
	else
	{
		if(id)
			element.style.backgroundColor = '#FFBBBB';
		for (i=0; i<element.length; i++) {
			if(element.options[i].value==0)
			{
				element.options[i].selected = true;
				break;
			}
		}
	}
}

function jumpselect_id(id, element)
{
	var found = false;
	if(id)
	{
		for (i=0; i<element.length; i++)
		{
			if(element.options[i].id==id)
			{
				element.options[i].selected = true;
				found = true;
				break;
			}
		}
	}

	if(found)
	{
		element.style.backgroundColor = '#ffffff';
	}
	else
	{
		if(id)
			element.style.backgroundColor = '#FFBBBB';
		for (i=0; i<element.length; i++) {
			if(element.options[i].id==0)
			{
				element.options[i].selected = true;
				break;
			}
		}
	}
}

function checkartnr(element, button)
{
	if(element.value.match(/\d{7}[+|-]\d{6}/))
	{
		element.style.backgroundColor = '#ffffff';
		button.disabled = false;
	}
	else
	{
		element.style.backgroundColor = '#FFBBBB';	
		button.disabled = true;
	}
}

function insertAtCursor(myField, myValue)
{
	if(myValue == "p")
		myValue = '<p style=\"padding-left: '+prompt('Please enter left spacing in pixels!')+'px;\">'+prompt('Please enter paragraph text!')+'</p>'
	else if(myValue == "i")
		myValue = '<i>'+prompt('Please enter your text!')+'</i>';
	else if(myValue == "li")
		myValue = '<li>'+prompt('Please enter your text!')+'</li>';
	else if(myValue == "br")
		myValue = '<br>';
	else if(myValue == "b")
		myValue = '<b>'+prompt('Please enter your text!')+'</b>';
	else if(myValue == "u")
		myValue = '<u>'+prompt('Please enter your text!')+'</u>';
	
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	}
	else
	{
		myField.value += myValue;
	}
}

function displayHTML(name, code)
{
	var Name = "M+F Helpdesk Preview";
	var Fensteroptionen = "toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0";
	var Breite = 800;
	var Hoehe = 800;
	win = window.open("", 'Name', Fensteroptionen + ',width=' + Breite + ',height=' + Hoehe);
	//IE FIX?	
	//win.document.open();
	win.document.write('<html><head><title>M+F Helpdesk</title>');
	win.document.write('<link rel=stylesheet href="https://www.mfx-systems.de:1000/v2/mf.css" type=text/css>');
	win.document.write('<script src="mf.js" type="text/javascript" language="javascript"></script></head>');
	win.document.write('<body><form name=preview><table class="tableshow" style="width: 585px;" border=0>');
	win.document.write('<tr><td class="tdshow_top"><img src=gfx/help.png border=0> <b>M+F Helpdesk v1.00b</b></td></tr>');
	win.document.write('</table><br>');
	win.document.write('<table class="tableshow" style="width: 785px;" border=0>');
	win.document.write('<tr><td class="tdshow_top" align=center><b>Available help topics for Helpdesk entry</b></td></tr>');
	win.document.write('<tr><td class="tdshow1" style="border-bottom: 1px solid black;" valign=top>');
	win.document.write('<img src=gfx/u.gif border=0></a> <b>');
	win.document.write("" + name.value + "");
	win.document.write('</b></a></td></tr>');
	win.document.write('<tr>');
	win.document.write('<td class="tdshow0" style="padding: 5px;" valign=top>');
	win.document.write("" + code.value + "");
	win.document.write('</td></tr></table></form></body></html>');
	win.document.close();
}

function popup(src)
{
	var URL = src;
	var Name = "M+F Helpdesk";
	var Fensteroptionen = "toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=0";
	var Breite = 800;
	var Hoehe = 800;
	window.open(URL, 'Name', Fensteroptionen + ',width=' + Breite + ',height=' + Hoehe);
}

function copyForm(html, pic)
{
	pic.data_name.value		=	html.data_name.value;
	pic.data_name_eng.value	=	html.data_name_eng.value;
	pic.data_order.value	=	html.data_order.value;
	pic.data_text.value		=	html.data_text.value;
	pic.data_text_eng.value	=	html.data_text_eng.value;
}

function htmlImg(select, txt)
{
	var number = select.selectedIndex;
	var img = new Image;
	var scale = 0;

	if(select.options[number].value != 0)
	{
		var title = prompt("Please enter Image title");

		if(number)
			insertAtCursor(txt, '<img src="'+select.options[number].value+'" border="0" title="'+title+'">');
	}
}

