// JavaScript Document - Onur Güngören - acocon GmbH 2008

function catcher(){
	var randomnumber=Math.floor(Math.random()*5);
	d = document.getElementById('img_catch').src;
	z = false;
	
	if(d.indexOf('#') == -1){
 		c = d.substr(d.indexOf('_')+1, 1);
 		while(z != 'true'){
 		if( c != randomnumber){
 		a = "/system/modules/de.acocon.modules.templates/resources/layout/catch/catch_" + randomnumber + ".gif";
 		document.getElementById('img_catch').src = a;
 		z = 'true';
 		}else{
 		randomnumber=Math.floor(Math.random()*5);
 		}
 		}
 	
 	}else{
 	a = "/system/modules/de.acocon.modules.templates/resources/layout/catch/catch_" + randomnumber + ".gif";
 	document.getElementById('img_catch').src = a;
	}	
}

function kontaktOn(){
document.getElementById('kontaktLayer').style.display = 'block';
document.getElementById('kontaktLayerShadow').style.display = 'block';
catcher();
}

function kontaktOff() {
document.getElementById('kontaktLayer').style.display = 'none';
document.getElementById('kontaktLayerShadow').style.display = 'none';
}

function uriSplit(){
var a = location.href.split("/"),b,c;
	for(i = 0; i < a.length; i++){
		if(a[i].match(/.\.html/)){
			b = a[i];
		}
if(a[i].match(/akademie/)){
c = a[i];
	}
}
var d = c + "/" + b;
return d;
}


function switchHeader(n,img){

var a = uriSplit().split("/"), b;
for(i = 0; i < a.length; i++){
if(a[i].match(/.\.html/)){
  b = a[i];
}}


  if(uriSplit().match(/akademie\/index\.html/)){
   document.getElementById('kursframe').src = '<%=domServer %>/acocon/WebView?hdetail=' + n + '&katdetail=1&art=1';
  }else{
    document.getElementById('kursframe').style.display = 'block';
  	document.getElementById(b).className = '';
  	document.getElementById('index.html').className = 'selected';
  	document.getElementById('headLine').style.display = 'none';
  	document.getElementById('contentElement').style.display = 'none';
    document.getElementById('kursframe').src = '<%=domServer %>/acocon/WebView?hdetail=' + n + '&katdetail=1&art=1';
}

}


function pruefe() {

var a = uriSplit().split("/"), b;
for(i = 0; i < a.length; i++){
if(a[i].match(/.\.html/)){
b = a[i];
}}
   if(!uriSplit().match(/akademie\/index\.html/)){

	document.getElementById('kursframe').style.display = 'block';
	document.getElementById(b).className = '';
	document.getElementById('index.html').className = 'selected';
	document.getElementById('headLine').style.display = 'none';
	document.getElementById('contentElement').style.display = 'none';
	return true;
   }

}

function resIframe(){

if(document.all&&!window.opera) {
     var a=document.all.detail;
     kursframe.document.body.scroll='no';
   } else {
     var a=document.getElementsByName('kursframe')[0];
     a.scrolling='no';
   }
   var a=document.getElementsByName('kursframe')[0];
   kursframe.document.getElementsByTagName('body')[0].style.overflow='hidden';
   var b=kursframe.document.getElementById('portalColumnMain');

   if(a.style.height != eval(b.offsetHeight+35)+'px') {
      a.style.height=eval(b.offsetHeight+35)+'px';
   }

}

function iresDelay(){
window.setTimeout("resIframe()", 150);

var pfad = parent.kursframe.location.href;
if(pfad == "<%= domServer %>/acocon/WebView" || pfad == "<%= domServer %>/acocon/search_results.jsp" ){
return true;
}else{
var a = parent.kursframe.location.href.split("&"), b,c,d,img;

  for( i = 0; i < a.length; i++){
    if(a[i].match(/hdetail/)){
    b = a[i];
    }
  }
c = b.split("="), d;

  for(y = 0; y < c.length; y++){
    if(c[y].match(/[0-9]/)){
    d = c[y];
    }
  }

if(d == 1){
img = "microsoft";
}  
if(d == 2){
img = "lotus";
}
if(d == 3){
img = "citrix";
}
if(d == 4){
img = "itil";
}
var imgpf = '<%= img_pfad %>/header/acocon_' + img + '.jpg';
  
  for(o = 1; o <= 4; o++){
    if(o == d){
      document.getElementById('li'+d).className = img;
      document.getElementById('hImage').src = imgpf;
    }else{
      document.getElementById('li'+o).className = '';
      }
  }

}
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#F8B333'; 
        error = "You didn't enter a username.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#F8B333'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCheckbox(fld) {
    var error = "";
 
    if (fld.checked == 0) {
        fld.style.background = '#F8B333'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#F8B333';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#F8B333';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#F8B333';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function submitter() {
theForm = document.forms['kontaktWeb'];
var reason = "";

  reason += validateUsername(theForm.firma);
  reason += validateUsername(theForm.firstname);
  reason += validateUsername(theForm.lastname);
  reason += validateUsername(theForm.street);
  reason += validateUsername(theForm.number);
  reason += validateUsername(theForm.plz);
  reason += validateUsername(theForm.ort);
  reason += validateCheckbox(theForm.agbcheck);

  reason += validateEmail(theForm.email);
      
  if (reason != "") {
    alert("Bitte überprüfen Sie ihre Angaben!\n");
    return false;
  }

  theForm.submit();
}
