function showPictureLink(link, id, targetWidth, targetHeight, spacer, bottomSpacer, vorname, nachname) {
   var relId = "kader";

   var minimalFrameWidth = 480;

   var winW = 630, winH = 460;
   var minimalBorderHorizonral = 2*15, minimalBorderVertical = 2*30;

   if (parseInt(navigator.appVersion)>3) {
       if (navigator.appName=="Netscape") {
           winW = window.innerWidth;
           winH = window.innerHeight;
       }
       if (navigator.appName.indexOf("Microsoft")!=-1) {
           winW = document.body.offsetWidth;
           winH = document.documentElement.clientHeight;
           // this only ready when the body tag is already rendered: winH = document.body.offsetHeight;
       }
   }

   while ((targetWidth + 2 * spacer > winW - minimalBorderHorizonral) || (targetHeight + bottomSpacer + spacer > winH - minimalBorderVertical)) {
       //the target window is not that wide as we wanted the picture to be
       targetWidth = targetWidth / 100 * 80;
       targetHeight = targetHeight / 100 * 80;
   }

   var frameWidth = targetWidth + 2 * spacer;
   if ( frameWidth < minimalFrameWidth) { frameWidth = minimalFrameWidth; }

   var frameHeight = targetHeight + bottomSpacer + spacer;

   var badBrowser = (/MSIE/.test(navigator.userAgent) && navigator.platform == "Win32");
   if(badBrowser) {
      document.write('<a href='+link+'&width='+frameWidth +'&height='+frameHeight +'&documentId='+id+'&imgW='+targetWidth+'&imgH='+targetHeight+'&KeepThis=true&TB_iframe=true class="thickbox" rel="'+relId+'">'+vorname+' '+nachname+'</a>');
   }
   else {
      document.write('<a href='+link+'&width='+frameWidth +'&height='+frameHeight +'&documentId='+id+'&imgW='+targetWidth+'&imgH='+targetHeight+' class="thickbox" rel="'+relId+'">'+vorname+' '+nachname+'</a>');
   }
}

function checkFields() {
    if ( checkField('name') && checkEmail('email1', 'email2') && checkField('betreff') && checkField('text') ) {
        return true;
    }
    else {
        alert(unescape("Bitte f%FCllen Sie alle Pflichtfelder aus. Fehlerhaft ausgef%FCllte Felder sind mit einem roten Stern markiert."));
        return false;
    }
}

function checkField(name) {
   //alert("name of field is: "+name);
    var length = document.getElementById(name).value.length;
    if (length == 0) { 
        document.getElementById(name+"Star").style.color = "red"; 
        return false;
    }
    else { 
        document.getElementById(name+"Star").style.color = "black"; 
        return true;
    }
}

function checkEmail(name, nameToCompare) {
    var length = document.getElementById(name).value.length;

    var rval = false;
    if (length == 0 || !isValidEmail(document.getElementById(name).value) ) { 
        rval = false;
        document.getElementById(name+"Star").style.color = "red"; 
    }
    else { 
        rval = true;
        document.getElementById(name+"Star").style.color = "black"; 
    }
    var secRval = checkSecondEmail(nameToCompare, name);

    return rval && secRval;
}

function checkSecondEmail(name, nameToCompare) {
    var oneVal = document.getElementById(name).value;
    var otherVal = document.getElementById(nameToCompare).value;

    if (oneVal  == otherVal && isValidEmail(oneVal)) { 
        document.getElementById(name+"Star").style.color = "black"; 
        return true;
    }
    else { 
        document.getElementById(name+"Star").style.color = "red"; 
        return false;
    }
}

function isValidEmail(mailAdress) {
     var emailReg = "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$";
     var regex = new RegExp(emailReg);
     return regex.test(mailAdress);
}

function deleteConfirm(deleteLink, link) {
    var splittet = link.split('&');
    var filename = splittet[1].split('=')[1];
    var ans; 
    ans=window.confirm('Wollen sie '+filename+' wirklich loeschen?');
    if(ans) {
        window.location.href = deleteLink;
    }
}
