// JavaScript for www.erst.ch
// 27-December-2004

var emailIndex = -1;
var emailValue = "";
var xyz = "01234567890123456789012345";
var abc = "qazwsxedcrfvtgbyhnujmikolp";

function setInfoEmail (dummy) {
    var name = abc.charAt(21) + abc.charAt(17) + abc.charAt(10) + abc.charAt(23);
    setEmail (dummy, name, "");
}

function setEricEmail (dummy) {
    var name = abc.charAt(6) + abc.charAt(9) + abc.charAt(21) + abc.charAt(8);
    name += '\u002e';
    name += abc.charAt(3) + abc.charAt(6) + abc.charAt(9) + abc.charAt(17);
    name += abc.charAt(24) + abc.charAt(15);
    setEmail (dummy, name, "");
}

function setStefanEmail (dummy) {
    var name = abc.charAt(4) + abc.charAt(12) + abc.charAt(6) + abc.charAt(10);
    name += abc.charAt(1) + abc.charAt(17);
    name += '\u002e';
    name += abc.charAt(4) + abc.charAt(8) + abc.charAt(16) + abc.charAt(1);
    name += abc.charAt(10) + abc.charAt(9) + abc.charAt(23) + abc.charAt(12);
    name += abc.charAt(16);
    setEmail (dummy, name, "");
}

function setRequestEmail (args) {
    var name = abc.charAt(21) + abc.charAt(17) + abc.charAt(10) + abc.charAt(23);
    setEmail (args, name, "?" + args);
}

function companyEmail() {
    var comp = '\u0040';
    comp += abc.charAt(6) + abc.charAt(9) + abc.charAt(4) + abc.charAt(12);
    comp += '\u002e';
    comp += abc.charAt(8) + abc.charAt(16);
    return comp;
}

function setEmail (dummy, correctEmail, args) {
    for (i = 0; i < document.links.length; i++) {
        var href0 = document.links[i].href;
        var href = href0.replace ("%20", " ");
        while (href0 != href) {
            href0 = href;
            href = href0.replace ("%20", " ");
        }
        if (href.search(dummy) != -1) {
            emailIndex = i;
            emailValue = dummy;
            document.links[i].href = abc.charAt(20) + abc.charAt(1) +
                abc.charAt(21) + abc.charAt(24) + "to:" + correctEmail + companyEmail() + args;
        }
    }
}

function setImageEmail() {
    if (emailIndex >= 0)
        document.links[emailIndex].href = emailValue;
}


// 13-April-2005
// -------------

// Check if the value field of an object with given name is not empty.
function check (obj, name) {
    if (obj.name == name && obj.value == "") {
        alert ("Das Feld '" + obj.name + "' muss ausgefüllt werden.");
        return false;
    }
    return true;
}

// Check all mandatory fields and submit form.
function submitContactForm (name) {
    var form = document.forms[name];
    if (checkContactForm (form))
        form.submit();
}

// Check for empty mandatory fields.
function checkContactForm (form) {
    for (i = 0; i < form.elements.length; i++) {
        var o = form.elements[i];
        if (!check (o, "Vorname")) return false;
        if (!check (o, "Nachname")) return false;
        if (!check (o, "Firma")) return false;
        if (!check (o, "Adresse")) return false;
        if (!check (o, "Postleitzahl")) return false;
        if (!check (o, "Ort")) return false;
        if (!check (o, "Land")) return false;
        if (!check (o, "Email")) return false;
        if (!check (o, "Inhalt der Anfrage")) return false;        
    }
    return true;
}

// 20-March-2007
// -------------
function view_address(id) {
  address_to_replace = document.getElementById(id).firstChild;
  real_address = address_to_replace.nodeValue.replace("[at]", "@");
  address_to_replace.nodeValue = real_address;
  address_to_replace.parentNode.setAttribute("href", "mailto:"+real_address);
}

function view_addresses() {
  if (document.getElementsByTagName) {
    var a = document.getElementsByTagName("a");
    var i;
    for (i = 0; i < a.length; i++) {
      if (a[i].className && a[i].className == "e") {
	address_to_replace = a[i].firstChild;
	real_address = address_to_replace.nodeValue.replace("[at]", "@");
	address_to_replace.nodeValue = real_address;
	address_to_replace.parentNode.setAttribute("href", "mailto:"+real_address);
      }
    }
  }
}

window.onload = function() {
  view_addresses();
}

// 11-November-2007
// ----------------
// Browser independent function to get an element given its id.
function getElementById(id) {
    if( window.mmIsOpera ) return(document.getElementById(id));
    if (document.all) return(document.all[id]);
    if (document.getElementById) return(document.getElementById(id));
    return(false);
}

// Show/hide selected data block and arrow images.
function focusF(id) {		
    var children = getElementById(id).childNodes;
    for(i=0;i<children.length;i++) {
        var child = children[i];
        if(child.nodeName == 'div' || child.nodeName == 'DIV') {
            if(child.id == 'data') {
	        if (child.style.display == 'none') {
                  child.style.display = 'block';
	        } else {
                  child.style.display = 'none';
	        }
	    }
            if(child.id == 'arrow') {
                var images=child.getElementsByTagName('img');
                if (images['arrow_right'].style.display == 'none') {
                    images['arrow_right'].style.display = 'inline';
		} else {
                    images['arrow_right'].style.display = 'none';
		}
                if (images['arrow_down'].style.display == 'none') {
                    images['arrow_down'].style.display = 'inline';
		} else {
                    images['arrow_down'].style.display = 'none';
		}
            }
        }
    }
}
