//__________________________________copyright_________________________________
//_______________________________saw mediendesign_____________________________
//_______________________________www.saw-media.de_____________________________
//__________________________________Stand 01/03_______________________________






//__________________________________variable__________________________________

var timer;
var Lmax;
var Lmin;
var x = 0;
var xs = 0;
var speed=50;
bw=new verifyCompatibleBrowser() 
var initialised;
var sec;
var warner;

//___________________________________scripts__________________________________

function MM_callJS(jsStr) { 
  return eval(jsStr)
}

function checkform() {
  var message = "Folgende Felder wurden nicht korrekt ausgefüllt!\n\n";
  var proceed = true;
  if (document.myform.anrede.options[document.myform.anrede.selectedIndex].text == '') { 
    message = message + "Anrede\n";
    proceed = false; 
  }
  if (document.myform.name.value.length == 0) { 
    message = message + "Name\n";
    proceed = false; 
  }
  if (document.myform.vorname.value.length == 0) { 
    message = message + "Vorname\n";
    proceed = false;
  }
  if (document.myform.strasse.value.length == 0) { 
    message = message + "Straße\n";
    proceed = false;
  }
  if (document.myform.plz.value.length < 5) { 
    message = message + "PLZ 5-stellig, für das Ausland bspw. Schweiz CH-xxxx\n";
    proceed = false; 
  }
  //if (document.myform.plz.value.match("[^0-9]")) { proceed = false; }
  if (document.myform.ort.value.length == 0) { 
    message = message + "Ort\n";
    proceed = false; 
  }
  if (document.myform.mail.value.length == 0) { 
    message = message + "Email\n";
    proceed = false; 
  } else {
    if(!document.myform.mail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.at)|(\.de)|(\.ch)|(\.gov)|(\.org)|(\.info)|(\..{2,2}))$)\b/gi)) { 
      message = message + "Email\n";
      proceed = false; 
    }
  }
  if (document.myform.user.value.length == 0) { 
    message = message + "Benutzername\n";
    proceed = false; 
  } else {
    for (index = 0; index < document.myform.user.value.length; index++) {
      if (document.myform.user.value.charAt(index) == ' ') {
        message = message + "Benutzername (Leerzeichen)\n";
        proceed = false;
      }
    }
  }
  if (document.myform.passw.value.length == 0) { 
    message = message + "Passwort\n";
    proceed = false; 
  } else {
    for (index = 0; index < document.myform.passw.value.length; index++) {
      if (document.myform.passw.value.charAt(index) == ' ') {
        message = message + "Passwort (Leerzeichen)\n";
        proceed = false;
      }
    }
  }
  if (document.myform.gebdat.value.length != 0) {
    if(!document.myform.gebdat.value.match(/\d\d\.\d\d\.\d\d\d\d/)) { 
      message = message + "Geburtsdatum Format TT.MM.JJJJ";
      proceed = false; 
    }
  }
  if (!proceed) {
    alert(message);
    return false;
  } 
  else {
    return true;
  }
}

function checkformmail() {
  var proceed = true;
  if (document.myform.betreff.value.length == 0) { proceed = false; }
  if (document.myform.nachricht.value.length == 0) { proceed = false; }
  if (document.myform.attachment.value.length == 0) { proceed = false; }
  if (document.myform.datum.value.length == 0) { proceed = false; }
  if(!document.myform.datum.value.match(/\d\d\.\d\d\.\d\d\d\d/)) { proceed = false; }
  if (!proceed) {
    alert("Die gemachten Eingaben sind nicht vollständig!");
    return false;
  } 
  else {
    return true;
  }
}

function studie() {
  regx = /\\/gi;
  datei = "";
  datei_2 = "";
  datei_3 = "";
  if (document.myform.attachment.value.match(regx)) {
    datei = document.myform.attachment.value.replace(regx, "*");
    wert = datei.lastIndexOf("*");
    datei = datei.substring((wert+1),datei.length);
    document.myform.file.value = datei;
    wert = datei.lastIndexOf(".");
    datei = datei.substring((wert+1),datei.length);
    document.myform.ext.value = datei;
  }
  if (document.myform.attachment_2.value.match(regx)) {
    datei_2 = document.myform.attachment_2.value.replace(regx, "*");
    wert_2 = datei_2.lastIndexOf("*");
    datei_2 = datei_2.substring((wert_2 + 1),datei_2.length);
    document.myform.file_2.value = datei_2;
    wert_2 = datei_2.lastIndexOf(".");
    datei_2 = datei_2.substring((wert_2 + 1),datei_2.length);
    document.myform.ext_2.value = datei_2;
  }
  if (document.myform.attachment_3.value.match(regx)) {
    datei_3 = document.myform.attachment_3.value.replace(regx, "*");
    wert_3 = datei_3.lastIndexOf("*");
    datei_3 = datei_3.substring((wert_3 + 1),datei_3.length);
    document.myform.file_3.value = datei_3;
    wert_3 = datei_3.lastIndexOf(".");
    datei_3 = datei_3.substring((wert_3 + 1),datei_3.length);
    document.myform.ext_3.value = datei_3;
  }
  if (checkformmail()) {
    return true;
  } else {
    return false;
  }
}

function MM_findObj(n, d) {
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
    x=MM_findObj(n,d.layers[i].document); 
    return x;
}

//___________________________________window___________________________________

function MM_opensaw(theURL,winName,titel,features,w,h) {  
  if (document.all) { 
    Fenster = window.open(theURL,winName,"width=755,height=400");
    Fenster.moveTo((screen.width/2)-(w/2),(screen.height/2)-(h/2));
    Fenster.focus();
  }
  else if(document.layers || document.getElementById) {
    Fenster = window.open(theURL,winName,"width=755,height=400");
    Fenster.moveTo((screen.width/2)-(w/2),(screen.height/2)-(h/2));
    Fenster.focus();
  }
}

function init() {
  if(document.all) {
    scrW = screen.width;
    scrH = screen.height;
    parent.window.outerHeight = screen.height;
    parent.window.outerWidth = screen.width;    
    parent.window.resizeTo( scrW, scrH );
    //parent.window.moveTo ( (scrW/2)-400, (scrH/2)-250 );
    parent.window.moveTo ( 0, 0 );
  }
}

function window_reload() {
  if(document.layers) { parent.window.location.replace('http://www.pisa-training.de');}
}

function MMframes() {
  if(top.frames.length == 0) { parent.window.location.replace('http://www.pisa-training.de');}
}

function MMframesflash() {
  //if(top.frames.length == 0) { parent.window.location.replace('../../index.html');}    
}

//________________________________navigation________________________________


function MMchangeframes4(URL1) {
  parent.window.location.replace(URL1);
}

function MMchangeframes3(URL1,F1,URL2,F2) {
  parent.frames[F1].location.replace(URL1);
  parent.frames[F2].location.replace(URL2);
}

function MMchangeframes2(URL1,F1,URL2,F2,URL3,F3,URL4,F4) {
  parent.frames[F1].location.replace(URL1);
  parent.frames[F2].location.replace(URL2);
  parent.frames[F3].location.replace(URL3);
  parent.frames[F4].location.replace(URL4);
}

function MMchangeframes(URL1,F1,URL2,F2,URL3,F3) {
  parent.frames[F1].location.replace(URL1);
  parent.frames[F2].location.replace(URL2);
  parent.frames[F3].location.replace(URL3);
}

//___________________________________layers_________________________________


function MMlayer(number,num, num2) { 
  if(document.layers) {
    for(i=0;i<number;i++)
      document.layers[i].visibility ="hide";
      if(num >= 0) {
        document.layers[num].visibility ="show";
      }
      if(num2 >= 0) {
        document.layers[num2].visibility ="show";
      }
  }
  else if (document.all) { 
    var layers=document.all.tags ("DIV");
    for(i=0;i<number;i++)
      layers[i].style.visibility ='hidden';
      if(num >= 0) {
        layers[num].style.visibility ='visible'; 
      } 
      if(num2 >= 0) {
        layers[num2].style.visibility ='visible'; 
      }  
  }
  else if (document.getElementById) {
    num = num + 1;
    num2 = num2 + 1;
    number = number + 1;
    for(i=1;i<number;i++)
      document.getElementById('Layer'+i).style.visibility ='hidden';
      if(num > 0) {
        document.getElementById('Layer'+num).style.visibility ='visible'; 
      } 
      if(num2 > 0) {
        document.getElementById('Layer'+num2).style.visibility ='visible'; 
      }  
  }
}

function verifyCompatibleBrowser() { 
  this.ver=navigator.appVersion 
  this.dom=document.getElementById?1:0 
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
  this.ie4=(document.all && !this.dom)?1:0; 
  this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;  
  this.ns4=(document.layers && !this.dom)?1:0; 
  this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
  return this 
} 
 
function ConstructObject(obj,nest) { 
  nest=(!nest) ? '':'document.'+nest+'.' 
  this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
  this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
  this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
  this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
  this.up=MoveAreaUp;this.down=MoveAreaDown; 
  this.MoveArea=MoveArea; this.x; this.y; 
  this.obj = obj + "Object" 
  eval(this.obj + "=this") 
  return this 
} 

function MoveArea(x,y){ 
  this.x=x;this.y=y 
  this.css.left=this.x 
  this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
  if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
  } 
} 

function MoveAreaUp(move){ 
  if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
  } 
} 
 
function PerformScroll(speed){ 
  if(initialised){ 
    loop=true; 
    if(speed>0) objScroller.down(speed) 
  else objScroller.up(speed) 
  } 
} 
 
function CeaseScroll(){   
  if(timer) clearTimeout(timer) 
  loop=false;
} 

function InitialiseScrollableArea(){ 
  objContainer=new ConstructObject('divContainer') 
  objScroller=new ConstructObject('divContent','divContainer') 
  objScroller.MoveArea(0,0) 
  objContainer.css.visibility='visible' 
  initialised=true; 
} 

//___________________________________images_________________________________


function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { 
  var d=document; 
  if(d.images){ 
   if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
    for(i=0; i<a.length; i++)
     if (a[i].indexOf("#")!=0){ 
      d.MM_p[j]=new Image; 
      d.MM_p[j++].src=a[i];
     }
  }
}

function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){
     document.MM_sr[j++]=x; 
     if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
   }
}

//___________________________________timer_________________________________


function test_duration(stop){  
  sec = sec + 1;
  if (stop == 0) {
    duration = (15 * 60);
    warning = (13 * 60);
    warner = 0;
    sec = 0;
  } else {
    if(sec >= warning && warner == 0) {
      warner = 1;
      alert("Noch 2 min.\nSchließen Sie bitte die Prüfung ab.\nSollten Sie Ihre Prüfungsfragen in 2 min nicht abgesendet\nhaben, wird dies automatisch vom System erfolgen.");
    } 
  }
  timerid = setTimeout("test_duration(1)",1000);
  if (sec >= duration) {
    clearTimeout(timerid);    
    document.myform.submit();
  }
}
