/* DHTML-Bibliothek */

var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false, Type = false, getme = 0, counter = 0;
var marked_row = new Array;
if (document.getElementById) 
{
  DHTML = true;
  DOM = true;
} 
else 
{
  if (document.all) 
  {
    DHTML = true;
    MSIE4 = true;
  } 
  else 
  {
    if (document.layers) 
    {
      DHTML = true;
       NS4 = true;
    }
  }
}
if (window.opera) 
{
  OP = true;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function moreFields() 
{
	var insertHere = document.getElementById('writeroot');
	var newFields, newFields1;
	if(!document.getElementById('ExtendedSearch2'))
	{
		newFields = document.getElementById('ExtendedSearch');
		newFields.id = 'ExtendedSearch2';
		insertHere.parentNode.insertBefore(newFields,insertHere);
		
		newFields1 = document.createElement("input");
		newFields1.id = 'moresearch';
		newFields1.name = 'moresearch';
		newFields1.type = 'hidden';
		newFields1.value = '1';
		//'<input id="moresearch" name="moresearch" type="hidden" value="1">';
		insertHere.parentNode.insertBefore(newFields1,insertHere);	
	}
	else
	{
		newFields1 = document.getElementById('ExtendedSearch2');
		insertHere.parentNode.removeChild(newFields1);
		newFields1.id = 'ExtendedSearch';
		insertHere.parentNode.insertBefore(newFields1,insertHere);
		
		newFields = document.getElementById('moresearch');
		insertHere.parentNode.removeChild(newFields);
	}
}

function select(value) 
{
	var insertHere = document.getElementById('writeroot');
	var newFields, newFields1;
	
	newFields = document.getElementById('infoEmployer');
	insertHere.parentNode.removeChild(newFields);
	insertHere.parentNode.insertBefore(infoArg[value],insertHere);
}

function getElement (Mode, Identifier, ElementNumber) 
{
  var Element, ElementList;
  if (DOM) 
  {
    if (Mode.toLowerCase() == "id") 
    {
      Element = document.getElementById(Identifier);
      if (!Element) 
      {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") 
    {
      ElementList = document.getElementsByName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) 
      {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") 
    {
      ElementList = document.getElementsByTagName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) 
      {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (MSIE4) 
  {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") 
    {
      Element = document.all(Identifier);
      if (!Element) 
      {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") 
    {
      ElementList = document.all.tags(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) 
  {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") 
    {
      Element = document[Identifier];
      if (!Element) {
        Element = document.anchors[Identifier];
      }
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "layerindex") 
    {
      Element = document.layers[Identifier];
      if (!Element) 
      {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) 
{
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    Attribute = Element[AttributeName]
    if (!Attribute) 
    {
       Attribute = false;
    }
    return Attribute;
  }
  return false;
}

function getContent (Mode, Identifier, ElementNumber) 
{
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) 
  {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    } else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) 
  {
    Content = Element.innerText;
    return Content;
  }
  return false;
}

function setContent (Mode, Identifier, ElementNumber, Text) 
{
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) 
  {
    return false;
  }
  if (DOM && Element.firstChild) 
  {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) 
  {
    Element.innerText = Text;
    return true;
  }
  if (NS4) 
  {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
}

function Menue(Type) 
{
	var DivId = "";
	if(Type == 1)
	{
		DivId = "ExtendedSearch";
	}
	else
	{
		DivId = "ExtendedSearch";
	}
	
  if (NS4) 
  {
    getElement("id", DivId).visibility = "show";
  } 
  else 
  {
    getElement("id", DivId).style.visibility = "visible";
  }
  Type = false;
}

function noMenue (Type) 
{
	var DivId = "";
	if(Type == 1)
	{
		DivId = "ExtendedSearch";
	}
	else
	{
		DivId = "ExtendedSearch";
	}

  if (NS4) 
  {
    getElement("id", DivId).visibility = "hide";
  } 
  else 
  {
    getElement("id", DivId).style.visibility = "hidden";
  }
}

function show () 
{
	getme = 1;
}

/**
 * enables highlight and marking of rows in data tables
 *
 */
function PMA_markRowsInit() 
{
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    var checkbox = null;
    var unique_id = null;
	var first = false;
    for ( var i = 0; i < rows.length; i++ ) 
    {
        if ( 'fmydatatr0' != rows[i].className.substr(0,10) && 'fmydatatr1' != rows[i].className.substr(0,10) ) 
        {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if (navigator.appName == 'Microsoft Internet Explorer') 
        {
            // but only for IE, other browsers are handled by :hover in css
            
            rows[i].onmouseover = function() 
            {
                this.className += 'hover';
            }
            rows[i].onmouseout = function() 
            {
                this.className = this.className.replace( 'hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) 
        {
            continue;
        }
        
        checkbox = rows[i].getElementsByTagName('input')[0];
        if(checkbox && checkbox.type == 'checkbox')
        {
	        unique_id = checkbox.name + checkbox.value;
	        if ( checkbox.disabled == false ) 
	        {
	             if (checkbox.checked == true &&( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] )) 
	             {
	                 rows[i].className += 'marked';
	                 marked_row[unique_id] = true;
	             }
	         }
	         //alert(checkbox + "3");
        }
        
       
        
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() 
        {
            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }
			//alert(unique_id); 
            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) 
            {
                this.className += 'marked';
            } 
            else 
            {
                this.className = this.className.replace('marked', '');
            }

            if ( checkbox && checkbox.disabled == false) 
            {
                checkbox.checked = marked_row[unique_id];
            }
            
            //alert(checkbox.checked + "3"); 
            first = checkbox.checked;
            for ( keyVar in marked_row ) 
            {
   				//alert(keyVar);
			}
        }
		
         // .. and checkbox clicks
        rows[i].onclick = function() 
        {
				for ( keyVar in marked_row ) 
            	{
   				  //alert(keyVar);
				}
    			checkbox = this.getElementsByTagName( 'input' )[0];
    			unique_id = checkbox.name + checkbox.value;
    			//alert(checkbox.checked + "2"); 
    			if (checkbox) 
            	{
	                // opera does not recognize return false;
	                if((typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id]) && checkbox.checked == true)
	                {
	                	//marked_row[unique_id] = true;
	                	//this.className += 'marked';
	                	checkbox.checked = first;
	                	//alert(unique_id+ "21");
		            }
		            else if(marked_row[unique_id] && checkbox.checked == false)
		            {
			            //marked_row[unique_id] = false;
		            	//this.className = this.className.replace('marked', '');
		            	//checkbox.checked = false;
		            	checkbox.checked = first;
		            	//alert(unique_id+ "22");
		            }
	            } 
        }
    }
}
window.onload=PMA_markRowsInit;

function setCheckbox(name) 
{
	var unique_id;
	var checkbox = document.getElementById(name);
	
	if(checkbox && checkbox.type == 'checkbox' )
	{
		if(checkbox.checked == true)
		{
			checkbox.checked = false;
			checkbox.style.bgColor = '#ffaa22';
		}
		else
		{
			checkbox.checked = true;
			checkbox.style.bgColor = '#ffaa22';
		}
	}
	return true;
}

/**
 * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
 *
 * @param   string   container_id  the container id
 * @param   boolean  state         new value for checkbox (true or false)
 * @return  boolean  always true
 */
function setCheckboxes( container_id, state ) {
    var checkboxes = document.getElementById(container_id).getElementsByTagName('input');

    for ( var i = 0; i < checkboxes.length; i++ ) 
    {
        if ( checkboxes[i].type == 'checkbox' ) 
        {
            checkboxes[i].checked = state;
        }
    }

    return true;
} // end of the 'setCheckboxes()' function

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) 
        {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) 
            {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) 
                {
                    rows[i].className += 'marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }

    return true;
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) 
    {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];
        if ( checkbox && checkbox.type == 'checkbox' ) 
        {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace('marked', '');
            marked_row[unique_id] = false;
        }
    }

    return true;
}