function changeCssAttrib(cssElement, attribute, value){
  //	thx to www.shanolson.net for assisting with this function. :)

  usedStyles = document.styleSheets;

  var cssList    = 0;
  var safariName = cssElement;
	
  if(cssElement.substring(0,1) == "#"){  //  this is needed for safari
    safariName = "*[ID\"" + cssElement.substring(1) + "\"]";
  }

  if(usedStyles){  //  ie, mozilla

    if(usedStyles[0]['rules']){  //  different way for different browsers  (IE)
      cssList = 'rules';
    } else if(usedStyles[0]['cssRules']) {  //  (Mozilla)
      cssList = 'cssRules';
    }

    for( i=0; i<usedStyles.length; i++){  //  walk through all loaded files
      theCSS = usedStyles[i][cssList];
      for(j=0;j<theCSS.length;j++){  //  content of all styles
      
       if(theCSS[j].selectorText == cssElement || theCSS[j].selectorText == safariName){  //  get the desired element
          theCSS[j].style[attribute] = value;
         }
       }
    }
  } else {  //  opera
    name = cssElement.substring(1);
    if(cssElement.substring(0,1) == "#"){
      elem = document.getElementById(name);
      elem.style[attribute] = value;
    } else {
      elems = document.getElementsByTagName("div");
      for(i=0;i<elems.length;i++){
        if(elems[i].getAttribute("class") == name){
          elems[i].style[attribute] = value;
        }
      }
    }
  }
}

function resize(){

  var bottomBorder = 2;
  
  //  get size of the page and of some elements
  var  y_used = document.body.scrollHeight;    //  used height

  if(window.innerHeight){  //  Mozilla, Opera
    y_possible = window.innerHeight;
    y_used += 1;
  } else if(document.body.parentNode.offsetHeight){  //  Internet Explorer
//    y_possible = document.body.offsetHeight;  //  possible height
    y_possible = document.body.parentNode.offsetHeight;  //  possible height
    y_used += 2;
    y_possible -= 3;
  }

  if(y_used < (y_possible)){  //  with scrollbars
    y = y_possible;
  } else {  //  content fits in screen
    y = y_used;
  }
	
  //  here we change the sizes of the elements
  //  this works only with classes in safari!!!!!
  changeCssAttrib('#columnLeft', 'height', (y - bottomBorder) + "px");
  changeCssAttrib('#columnRight', 'height', (y - bottomBorder) + "px");
  changeCssAttrib('#navigation', 'height', (y - 126 - bottomBorder + "px"));
}

function setLabelClass(elems,idFor,newClass){
  
  for(j=0;j<elems.length;j++){
    if(elems[j].getAttribute('for','false') == idFor|| elems[j].getAttribute('htmlfor','false') == idFor){
      elems[j].className = newClass;
    }
  }
}

function dealFormError(form,missingFields, wrongEmails, wrongPassword){
  
  /*
    This function highlights the missing mandatory fields and their label
  */
  var labels = document.getElementsByTagName('label');
  var wrongFields = missingFields.concat(wrongEmails);
  
  //  reset the styles of the form-elements.
  if(self.oldFields){
    for(i=0;i<oldFields.length;i++){
      form[oldFields[i]].className = oldClasses[i];
      setLabelClass(labels,oldFields[i],"");
    }
  }

  if(wrongFields.length>0){

    oldFields = new Array();
    oldClasses = new Array();
    for(i=0;i<wrongFields.length;i++){
      oldFields.push(wrongFields[i]);
      oldClasses.push(form[wrongFields[i]].className);
      form[wrongFields[i]].className = form[wrongFields[i]].className + " " + "formError";
      setLabelClass(labels,wrongFields[i],"formError");
    }
  }
  
  msg = "Das Formular konnte nicht abgeschickt werden.";
  if(missingFields.length>0){
    msg += "\nBitte füllen Sie alle Pflichtfelder aus.";
  }
  if(wrongEmails.length>0){
    msg += "\nWenn Sie Emailadressen eingeben, müssen diese syntaktisch korrekt sein.";
  }
  if(wrongPassword){
    msg += "\nDie Passwörter müssen mind. 4 Zeichen groß sein und miteinander übereinstimmen.";
  }
  alert(msg);
}

function openBrWindowFever(theURL,winName,features,ref,center){
  eval("var "+winName);	if (eval(winName)==true && !winName.closed)
  {winName.focus();}else{if(ref){
  var refURL=theURL+"?URL="+document.location;}else{var refURL=theURL;}
  if(center!="vals"){a=new Array();a=center.split('|');
  t=((screen.height)-a[0])/2;l=((screen.width)-a[1])/2;
  features=features+",top="+t+",left="+l;}
  winName=window.open(refURL,winName,features);
  winName.focus();winName = true;}
}

function CheckSupportFormular()
{
  with(document.forms[0])
  {
    if(vorname.value == "")
    {
      vorname.focus();
      alert("Bitte geben Sie Ihren Vornamen an.");
      return false;
    }
    if(nachname.value == "")
    {
      nachname.focus();
      alert("Bitte geben Sie Ihren Nachnamen an.");
      return false;
    } 
    if(email.value == "")
    {
      email.focus();
      alert("Bitte geben Sie Ihre E-Mail-Adresse an.");
      return false;
    }
    if(email.value != "")
    {
      reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
      res = (reg.test(email.value));
      if(!res)
      {
        email.focus();
        alert("Bitte überprüfen Sie Ihre E-Mail-Adresse.");
        return false;
      }
    }

    if(mitteilung.value == "")
    {
      mitteilung.focus;
      alert("Bitte geben Sie Ihre Mitteilung ein.");
      return false;
    }

    else
      submit();
  }
}

function CheckGaestebuchFormular()
{
  with(document.forms[0])
  {
    if(elements["we_ui_we_global_form[Name]"].value.length == 0)
    {
      alert("Bitte geben Sie Ihren Namen ein!");
      elements["we_ui_we_global_form[Name]"].focus();
      return false;
    }
    if(elements["we_ui_we_global_form[EMail]"].value.length != 0)
    {
      reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
      res = (reg.test(elements["we_ui_we_global_form[EMail]"].value));
      if(!res)
      {
        elements["we_ui_we_global_form[EMail]"].focus();
        alert("Bitte überprüfen Sie Ihre E-Mail-Adresse.");
        return false;
      }
    }
    if(elements["we_ui_we_global_form[Ort]"].value.length == 0)
    {
      alert("Bitte geben Sie Ihren Ort ein!");
      elements["we_ui_we_global_form[Ort]"].focus();
      return false;
    }
    if(elements["we_ui_we_global_form[Text]"].value.length == 0)
    {
      alert("Bitte geben Sie einen Text ein!");
      elements["we_ui_we_global_form[Text]"].focus();
      return false;
    }
    else
    {
      submit();
    }
  }
}

function HideLinkFocus()
{
  if(document.all)
  {
    for(var i = 0; i < document.links.length; i++)
     document.links[i].hideFocus = true;
  }
}
