/* Softlayer
 * Adaption von lightbox:
	Lightbox JS: Fullsize Image Overlays 
	by Lokesh Dhakar - http://www.huddletogether.com

	For more information on this script, visit:
	http://huddletogether.com/projects/lightbox/
 */
 var inity;

function softlayer_showAjax( id )
{
  var objOverlay = document.getElementById('overlay');
  if ( objOverlay==null ) init_softlayer();
  softlayer_setwaiting();

  var container = document.getElementById( 'lightboxContainer' );
  ajax_req( '/ajax/'+encodeURIComponent(id)+'.html', '', function(res)
  {
    container.innerHTML = res;
    softlayer_showfull();
    window.setTimeout( function() { focusInputRoot( container ) }, 1 );
  } );
  return false;
}

function softlayer_showURL( url )
{
  var objOverlay = document.getElementById('overlay');
  if ( objOverlay==null ) init_softlayer();
  softlayer_setwaiting();

  var container = document.getElementById( 'lightboxContainer' );
  ajax_req( url, '', function(res)
  {
    container.innerHTML = res;
    softlayer_showfull();
    window.setTimeout( function() { focusInputRoot( container ) }, 1 );
  } );
  return false;
}

function softlayer_showImage( url )
{
  var objOverlay = document.getElementById('overlay');
  if ( objOverlay==null ) init_softlayer();
  softlayer_setwaiting();

  var container = document.getElementById( 'lightboxContainer' );

	var imgPreload = new Image();

	imgPreload.onload=function()
	{
    var img = document.createElement( 'img' );
    while ( container.hasChildNodes() )
      container.removeChild( container.firstChild );
    img.src = imgPreload.src;
    img.onclick = softlayer_close;
    container.appendChild( img );
    softlayer_showfull();
  };

	imgPreload.src = url;
  return false;
}

function softlayer_showContent( content )
{
  var objOverlay = document.getElementById('overlay');
  if ( objOverlay==null ) init_softlayer();

  var container = document.getElementById( 'lightboxContainer' );
  container.innerHTML = content;
  softlayer_showfull();
  window.setTimeout( function() { focusInputRoot( container ) }, 1 );
  return false;
}

function softlayer_setwaiting()
{
  var objOverlay = document.getElementById('overlay');
  var objLoadingImage = document.getElementById('loadingImage');
  var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

  if (objLoadingImage) {
    objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
    objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
    objLoadingImage.style.display = 'block';
  }

  objOverlay.style.height = (arrayPageSize[1] + 'px');
  objOverlay.style.display = 'block';
}

function softlayer_showfull()
{
  var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
  var objLoadingImage = document.getElementById('loadingImage');
  if (objLoadingImage) objLoadingImage.style.display = 'none';

  var arrayPageSize = getPageSize();

  objLightbox.style.display = 'block';
  objOverlay.style.height = (arrayPageSize[1] + 'px');
  objOverlay.style.display = 'block';

  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  document.body.onkeypress = function(event)
  {
    if (event && event.keyCode)
    {
        if ( event.keyCode == 27 ) softlayer_close();
    }
  };
  /* Box als hidden markieren, um flickern zu vermeiden */
  objLightbox.style.visibility = 'hidden';
  window.setTimeout( function()
  {
    objLightbox.style.visibility = '';
    if ( arrayPageSize[3] - objLightbox.offsetHeight < 35 )
      objLightbox.style.top =  '35px';
    else
      objLightbox.style.top =  ( arrayPageScroll[1] + ( arrayPageSize[3] - objLightbox.offsetHeight )/3 )+ 'px';
    objLightbox.style.left = ( arrayPageSize[0] - objLightbox.offsetWidth )/2 + 'px';
  }, 1 );
}

function softlayer_close()
{
	var objLightbox = document.getElementById('lightbox');
  var objLoadingImage = document.getElementById('loadingImage');
  var objOverlay = document.getElementById('overlay');

  document.body.onkeypress = null;

  objLightbox.style.display = 'none';
  if (objLoadingImage) objLoadingImage.style.display = 'none';
  objOverlay.style.display = 'none';
  inity = 0;
  return false;
}

function init_softlayer()
{
  var objBody = document.getElementsByTagName("body").item(0);

  // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
  var objOverlay = document.createElement('div');
  objOverlay.setAttribute('id','overlay');
  //objOverlay.onclick = function () {hideLightbox(); return false;}
  objOverlay.style.display = 'none';
  objOverlay.style.position = 'absolute';
  objOverlay.style.top = '0';
  objOverlay.style.left = '0';
  objOverlay.style.zIndex = '90000';
  objOverlay.style.width = '100%';
  objOverlay.onclick = function() { softlayer_close(); };
  objBody.insertBefore(objOverlay, objBody.firstChild);

  var objLoadingImage = document.createElement("img");
  objLoadingImage.setAttribute('id','loadingImage');
  objLoadingImage.src = '/images/ovloading.gif';
  objLoadingImage.style.position = 'absolute';
  objLoadingImage.style.opacity = '0.8';
  objLoadingImage.style.zIndex = '150000';
  objOverlay.appendChild(objLoadingImage);

  var objLightbox = document.createElement('div');
  objLightbox.setAttribute('id','lightbox');
  objLightbox.style.display = 'none';
  objLightbox.style.position = 'absolute';
  objLightbox.style.zIndex = '100000';
  objBody.insertBefore( objLightbox, objBody.firstChild );

  var objCloseButton = document.createElement("img");
  objCloseButton.src = '/designs/default/images/close_head.gif';
  objCloseButton.setAttribute('id','closeButton');
  objCloseButton.style.position = 'absolute';
  objCloseButton.style.cursor = 'pointer';
  objCloseButton.onclick = function() { softlayer_close(); };
  objCloseButton.style.zIndex = '200000';
  objCloseButton.style.top = '5px';
  objCloseButton.style.right = '5px';
  objLightbox.appendChild(objCloseButton);

  objLightbox.className = 'rc_box';
  var last = objLightbox;
  for ( var i=1; i<7; i++ )
  {
    var div = document.createElement( 'div' );
    div.className = 'c'+i;
    last.appendChild( div );
    last = div;
  }
  objLightbox = last;
  objLightbox.setAttribute( 'id', 'lightboxContainer' );
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

/* Context ersetzen
 */
function replaceContent( elem, url, pram )
{
  var container = elem;
  var param = pram;
  var data = "";
  if( param ) {
    var pat = new RegExp(/[0-9]{0,3}(,|.)?[0-9]{0,2}/i);
    if (pat.exec(param.value)!=null)
      url = url + '?var=' + param.value;
  }
  var oldClass = container.className;
  container.className = container.className + ' waiting';
  var img = document.createElement( 'img' );
  var w = elem.offsetWidth;
  var h = elem.offsetHeight;
  if( h > 200 ) h = 200;
  img.className = 'wimg';
  img.style.top = ( ( h-10 ) / 2 )+'px';
  img.style.left = ( ( w-70 ) / 2 )+'px';
  img.style.opacity = '0.8';
  img.src = '/images/loading.gif';//'/images/loading_animation_liferay.gif';// '/images/Progressbar.gif'; //'/designs/default/images/loading.gif';
//  while ( container.hasChildNodes() )
//    container.removeChild( container.firstChild );
  if ( container.hasChildNodes() )
    container.insertBefore( img, container.firstChild );

  ajax_req( url, '', function(res)
  {
    container.className = oldClass;
    container.innerHTML = res;
  } );
  return false;
}

/* Ajax-Anfragen
 */
function getXmlHttpRequestObject()
{
  var xmlHttp = false;
  // Mozilla, Opera, Safari sowie Internet Explorer 7
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp) {
      // Internet Explorer 6 und älter
      try {
          xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
          try {
              xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              xmlHttp  = false;
          }
      }
  }
  return xmlHttp;
}

function ajax_req( src, data, callback )
{
  var xmlHttp = getXmlHttpRequestObject();
  if (xmlHttp)
  {
      xmlHttp.open('post', src, true );
      xmlHttp.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded; charset=utf-8' );

      xmlHttp.onreadystatechange = function ()
      {
          if (xmlHttp.readyState == 4)
          {
              resp = xmlHttp.responseText;
              callback(resp);
          }
      };
      xmlHttp.send('ajax_request=1&'+data);
  }
  return false;
}
function ajax_req_xml( src, data, callback )
{
  var xmlHttp = getXmlHttpRequestObject();
  if (xmlHttp)
  {
      xmlHttp.open('post', src, true );
      xmlHttp.setRequestHeader( 'Content-Type','application/x-www-form-urlencoded; charset=utf-8' );

      xmlHttp.onreadystatechange = function ()
      {
          if (xmlHttp.readyState == 4)
          {
              resp = xmlHttp.responseXML;
              callback(resp);
          }
      };
      xmlHttp.send('ajax_request=1&'+data);
  }
  return false;
}

/* Generelle Funktionen */
function focusInput()
{
  focusInputRoot( document );
}

function focusInputRoot( root )
{
  var input = false, textarea = false;

  var list = root.getElementsByTagName( 'input' );
  for ( var i=0; i<list.length; i++ )
  {
    var node = list[i];
    if ( node.type!='text' ) continue;
    var elem = node;
    while ( elem && elem.style.display!='none' )
    {
      if ( typeof elem.parentNode != "undefined" && elem.tagName.toLowerCase()!='body' )
        elem = elem.parentNode;
      else
        elem = false;
    }
    if ( elem && elem.style.display=='none' ) continue;
    input = node;
    break;
  }

  list = root.getElementsByTagName( 'textarea' );
  for ( var i=0; i<list.length; i++ )
  {
    var node = list[i];
    var elem = node;
    while ( elem && elem.style.display!='none' )
    {
      if ( typeof elem.parentNode != "undefined" && elem.tagName.toLowerCase()!='body' )
        elem = elem.parentNode;
      else
        elem = false;
    }
    if ( elem && elem.style.display=='none' ) continue;
    textarea = node;
    break;
  }

  if ( textarea!=false && input!=false )
  {
    if ( textarea.sourceIndex<input.sourceIndex )
      textarea.focus();
    else
      input.focus();
  } else if ( textarea!=false )
    textarea.focus();
  else if ( input!=false )
    input.focus();
}

function swap_content( span ) {
  displayType = ( $( span ).style.display == 'none' ) ? '' : 'none';
  $( span ).style.display = displayType;
  return false;
}
function swap_incontent( span ) {
  document.getElementById( span ).style.display = '';
  return false;
}
function swap_outcontent( span ) {
  document.getElementById( span ).style.display = 'none';
  return false;
}

function winopen( src, w, h )
{
  var x = (screen.availWidth - w)/2;
  var y = (screen.availHeight - h )/2;
  window.open( src, '_blank', 'scrollbars=yes, width='+w+', height='+h+', left='+x+', top='+y+', menubar=no, location=no, toolbar=no, status=no' );
  return false;
}

var visibleMenu = null;
var timeIv = 0;
function hideMenu()
{
  if ( visibleMenu==null ) return;
  visibleMenu.className = visibleMenu.className.replace( /\s+visible/, '' );
  visibleMenu = null;
}
function fadingMenu( elem )
{
  if ( timeIv )
  {
    window.clearTimeout(timeIv);
    timeIv = 0;
  }
  if ( visibleMenu!=null )
  {
    if ( visibleMenu==elem )
    {
      return;
    }
    hideMenu();
  }
  visibleMenu = elem;
  elem.className = elem.className+' visible';
}
function outfadingMenu( aelem )
{
  if ( timeIv>0 ) hideMenu();
  timeIv = window.setTimeout( function() {
    if ( timeIv>0 ) hideMenu();
    timeIv=0;
    }, 500 );
}

/* Suggest-Suche
*/
function Suggestor(elem, hide, tabs)
{
  this.queryField = elem;
//   elem.autocomplete = false;
  this.queryField.setAttribute("autocomplete","off");
  this.oldClass = '';
  this.inival = this.queryField.value;

  this.focus = function()
  {
    this.inival = this.queryField.value;
    this.oldClass = this.queryField.className;
    if ( this.queryField.className.match(/^(.*\b)\s*blured\s*(\b.*)$/) )
    {
      this.queryField.className = RegExp.$1 + ' '  + RegExp.$2;
      this.queryField.value = '';
    } else {
      this.queryField.select();
    }
  }
  this.blur = function()
  {
    if (this.queryField.value=='')
    {
      this.queryField.value = this.inival;
      this.queryField.className=this.oldClass;
    };
    var obj = this;
    window.setTimeout( function(){obj.hideDiv()}, 200 );
  }

  this.trigger_suggestor = function()
  {
    var value = this.queryField.value;
    var obj = this;
    if ( this.id )
    {
      window.clearTimeout( this.id );
    }
    this.id = window.setTimeout( function(){ obj.suggestor() }, 200 );
  }
  this.suggestor = function()
  {
    var idname =  this.queryField.id+'_res';
    var dest = document.getElementById( this.queryField.id+'_res' );
    var cat = document.getElementById( this.queryField.id+'_cat' );
    var poster = "film";
    if( cat.value )
      poster = cat.value;
    var obj = this;
    this.id = 0;
    var value = this.queryField.value;
    if ( value==this.lastReq ) return;

    this.lastReq = value;
    this.nextReq = false;

    if ( this.lastReq=='' || this.lastReq.length<3 )
    {
      this.hideDiv();
      return;
    }
    dest.innerHTML = '<div style="text-align:center"><img src="/images/loading.gif" style="padding:80px;opacity:0.8;" /></div>';
    if( currentSearchTab == poster  || tabs == 'notabs') {
      ajax_req( '/sucheEintrag.html', poster+'='+encodeURIComponent(this.lastReq), function(res)
      {
        dest.style.display = '';
	var options = { distance: 5, angle: 150, opacity: 0.7, nestedShadows: 10, color: '#000000'};
	Shadower.shadow(idname, options, true);
        dest.innerHTML = res;
      } );
    } else {
	$$('.' + 'shad' + idname).each(function(value, index){
    	value.style.display = 'none';
  	});
      	dest.innerHTML = '';
    }
  };

  this.hideDiv = function()
  {
    if( hide == 'hide' ) {
      var dest = document.getElementById( this.queryField.id+'_res' );
	$$('.' + 'shad' + this.queryField.id+'_res').each(function(value, index){
    	value.style.display = 'none';
  	});
      dest.style.display = 'none';
    }
  }

  this.startup = function()
  {
    var obj = this;
    this.focus();
    this.queryField.onfocus = function(){ obj.focus(); };
    this.queryField.onblur = function(){ obj.blur(); };
    this.queryField.onkeyup = function() { obj.trigger_suggestor(); };
  }
  this.startup();
}

function popupMenu( id, keep )
{
  var menu = document.getElementById( id );
  if ( menu )
  {
    if ( menu.style.display != 'none' )
    {
      menu.style.display = 'none';
      return;
    }
    var block = 0;
    if ( keep==true )
      menu.onclick = function(){
        var d = new Date();
        block = d.getTime();
        return true;
      };
    window.setTimeout( function() {
      document.body.onclick = function()
      {
        var d = new Date();
        if ( d.getTime()-block < 100 ) return true;
        menu.style.display = 'none';
        document.body.onclick = null;
        return true;
      } }, 100 );
    menu.style.display = 'block';
  }
}

function switchContent( box, id )
{
  var count = parseInt(document.getElementById(box + "-count").firstChild.data);
  var boxLayer = document.getElementById(box);
  var showLayer = document.getElementById(box + "-" + id);

  showLayer.className = showLayer.className.replace( /\btabcontent\b/, "tabcontent_active" );

  var showLayerTab = document.getElementById(box + "-" + id + "-tab");

  showLayerTab.className = 'tab_active';

  for( var i=0; i< count; i++)
  {
    if( id != i )
    {
      var hideLayer = document.getElementById(box + "-" + i);
    	hideLayer.className = showLayer.className.replace( /\btabcontent_active\b/, "tabcontent" );

    	var hideLayerTab = document.getElementById(box + "-" + i + "-tab");
    	hideLayerTab.style.backgroundPosition = "right top";

      if( i == 0 )
      {
      	hideLayerTab.className = 'tab_left';
      }
      else
      {
      	hideLayerTab.className = 'tab';
      }
    }
  }

  var nextBox = document.getElementById(box + "-" + (id+1) + "-tab");
  if ( nextBox != null )
  {
    nextBox.style.backgroundPosition = "left top";
  }


}
function textInputOnFocus(input)
{
  var val = input.value;
  var obj = input;
  var oldClass = input.className;
  if ( input.className.match(/^(.*\b)\s*blured\s*(\b.*)$/) )
  {
    input.onblur = function()
    {
      if (obj.value=='') { obj.value = val; obj.className=oldClass; };
    }
    input.className = RegExp.$1 + ' '  + RegExp.$2;
    input.value = '';
  } else {
    input.select();
  }
}

var currentSearchTab = "film";
function changeSearchTab(elem) {
  tab = document.getElementById( 'searchTab' + elem);
  tab.className = tab.className.replace( /\bsearchTab\b/, "searchTabActive" );
  hide = document.getElementById( 'mainsearchField_cat' );
  hide.value = elem;
  if( currentSearchTab != "" ) {
    oldtab = document.getElementById( 'searchTab' + currentSearchTab);
    oldtab.className = tab.className.replace( /\bsearchTabActive\b/, "searchTab" );
  }
  text = document.getElementById( 'mainsearchField_res' );
  text.innerHTML = "";
  currentSearchTab = elem;
  return false;
}


function SecondSuggestor(elem, hide, tabs)
{
  this.queryField2 = elem;
//   elem.autocomplete = false;
  this.queryField2.setAttribute("autocomplete","off");
  this.oldClass2 = '';
  this.inival2 = this.queryField2.value;

  this.focus2 = function()
  {
    this.inival2 = this.queryField2.value;
    this.oldClass2 = this.queryField2.className;
    if ( this.queryField2.className.match(/^(.*\b)\s*blured\s*(\b.*)$/) )
    {
      this.queryField2.className = RegExp.$1 + ' '  + RegExp.$2;
      this.queryField2.value = '';
    } else {
      this.queryField2.select();
    }
  }
  this.blur2 = function()
  {
    if (this.queryField2.value=='')
    {
      this.queryField2.value = this.inival2;
      this.queryField2.className=this.oldClass2;
    };
    var obj2 = this;
    window.setTimeout( function(){obj2.hideDiv2()}, 200 );
  }

  this.trigger_suggestor2 = function()
  {
    var value2 = this.queryField2.value;
    var obj2 = this;
    if ( this.id2 )
    {
      window.clearTimeout( this.id2 );
    }
    this.id2 = window.setTimeout( function(){ obj2.suggestor2() }, 200 );
  }
  this.suggestor2 = function()
  {
    var dest2 = document.getElementById( this.queryField2.id+'_res' );
    var cat2 = document.getElementById( this.queryField2.id+'_cat' );
    var poster2 = "film";
    if( cat2.value )
      poster2 = cat2.value;
    var obj2 = this;
    this.id2 = 0;
    var value2 = this.queryField2.value;
    if ( value2==this.lastReq2 ) return;

    this.lastReq2 = value2;
    this.nextReq2 = false;

    if ( this.lastReq2=='' || this.lastReq2.length<3 )
    {
      this.hideDiv2();
      return;
    }
    dest2.innerHTML = '<div style="text-align:center"><img src="/images/loading.gif" style="padding:80px;;opacity:0.8;" /></div>';
    if( currentSearchTab == poster2 || tabs == 'notabs' ) {
      inity = 0;

      ajax_req( '/sucheEintrag.html', poster2+'='+encodeURIComponent(this.lastReq2), function(res)
      {
        dest2.style.display = '';
        dest2.innerHTML = res;
      } );
    } else {
      dest2.innerHTML = '';
    }
  };

  this.hideDiv2 = function()
  {
    if( hide == 'hide' ) {
      var dest2 = document.getElementById( this.queryField2.id+'_res' );
      dest2.style.display = 'none';
    }
  }

  this.startup2 = function()
  {
    var obj2 = this;
    this.focus2();
    this.queryField2.onfocus = function(){ obj2.focus2(); };
    this.queryField2.onblur = function(){ obj2.blur2(); };
    this.queryField2.onkeyup = function() { obj2.trigger_suggestor2(); };
  }
  this.startup2();
}

function showInfoBox( span ) {
  displayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none';
  tab = document.getElementById( span + "tab" );
  if( displayType == 'none' )
    tab.className = tab.className.replace( /\bshowtab_active\b/, "showtab" );
  else {
    tab.className = tab.className.replace( /\bshowtab\b/, "showtab_active" );
  }
  document.getElementById( span ).style.display = displayType;
  return false;
}

function checkvalue( id ) {
  var tab = document.getElementById( id );
  if (tab.type=="text" || tab.type=="password" || tab.type=="textarea") {
    if (tab.value == "") {
      error = 1;
      tab.style.border = "1px solid maroon";
      tab.style.background = "#f6ebeb";
    } else {
      tab.style.background = '';
      tab.style.border = "1px solid #aaaaaa";
    }
  } else if (tab.type=="select-one" || tab.type=="select-one" || tab.type=="select-multiple") {
     if (tab.selectedIndex == 0) {
      error = 1;
      tab.style.background = "#f6ebeb";
      tab.style.border = "1px solid maroon";
    } else {
      tab.style.background = "#ffffff";
      tab.style.border = "1px solid #aaaaaa";
    }
  }
  return true;
}

function checkform( list ) {
  var error = 0;
  for ( var i=0; i<list.length; i++ )
  {
	  try {
      var tab = document.getElementById( list[i] );
      if (tab.type=="text" || tab.type=="password" || tab.type=="textarea") {
        if (tab.value == "") {
          error = 1;
          tab.style.border = "1px solid maroon";
          tab.style.background = "#f6ebeb";
        } else {
          tab.style.background = "#ffffff";
          tab.style.border = "1px solid #aaaaaa";
        }
      } else if (tab.type=="select-one" || tab.type=="select-one" || tab.type=="select-multiple") {
         if (tab.selectedIndex == 0) {
          error = 1;
          tab.style.background = "#f6ebeb";
          tab.style.border = "1px solid maroon";
        } else {
          tab.style.background = "#ffffff";
          tab.style.border = "1px solid #aaaaaa";
        }
      }
	  } catch(e) { }

  }
  if( error == 0 )
    return true;
  return false;
}


function clearform( list ) {
  for ( var i=0; i<list.length; i++ )
  {
	  try {
      var tab = document.getElementById( 'i' + list[i] );
      if (tab.type=="text" || tab.type=="password" || tab.type=="textarea") {
        tab.value = "";
      } else if (tab.type=="select-one" || tab.type=="select-one" || tab.type=="select-multiple") {
        tab.selectedIndex == 0;
      }
	  } catch(e) { }
  }
  return false;
}

function freeform( list ) {
  for ( var i=0; i<list.length; i++ )
  {
	  try {
      var tab = document.getElementById( 'i' + list[i] );
      tab.setAttribute('readonly', false, 'false');
	  } catch(e) { }
  }
  return true;
}

function blockform( list ) {
  for ( var i=0; i<list.length; i++ )
  {
	  try {
      var tab = document.getElementById( 'i' + list[i] );
      tab.setAttribute('readonly', true, 'true');
	  } catch(e) { }
  }
  return true;
}

var oldbackground = 'inone';
function changeBackground( id, highlight, background, color ) {
  var area = document.getElementById( id );
  var areaHigh = document.getElementById( highlight );
  var areaDown = document.getElementById( oldbackground );
  var areaForm = document.getElementById( 'ibackground' );
  if( background != '' ) {
    area.style.background = "url('/images/mails/" + background + "') no-repeat bottom right #ffffff";
    area.style.color = color;
  } else {
    area.style.background = "#ffffff";
    area.style.color = "#000000";
  }
  areaForm.value = background;
  areaDown.style.border = "1px solid #dddddd";
  areaHigh.style.border = "1px solid #000000";
  oldbackground = highlight;
  return false;
}