/*******************
 * API-KEY Weiche
 ******************/
 
function changeAPIkey() {
 
	/* maps0-maps1 = API-Key pro Hostname */
	var maps0; var maps1; var maps2; var maps3;
	
	var maps0 = "ABQIAAAAfIGpMZC3MM4FxKKNPhUGgRQKzLjeTDucmapv12DEWSVEnrFjCxRjrbPuBAnqRG7FpNWYcLbzubsLGA"; /* für energy-zone.com */
	var maps1 = "ABQIAAAAfIGpMZC3MM4FxKKNPhUGgRRTkaTGNO3ISzpNhP7TUkBeBRfIVBS6QFROukuGWGS_1LdgWwk7qf_98A"; /* für www.energy-zone.com */
 var maps2 = "ABQIAAAAfIGpMZC3MM4FxKKNPhUGgRQuxHWWjrkEyNWKz4K2tJTU00C_ERRS9gdZelCNzPS4os6z-4xQJhZTRA"; /* für rd-nfr-cms71 */
	var maps3 = "ABQIAAAAfIGpMZC3MM4FxKKNPhUGgRTzTYxhb2Pb9qoYixZNZrdkMfh_ghQBUz0_jVQjE_OGnFDNQJwa68ktdw"; /* für mainova.pinuts.de */
	
	/* HOSTNAME heraus bekommen und var key entsprechend mit dem passenden API-Key füllen */
	var apikey;
	
	if(window.location.hostname == "energy-zone.com") apikey = maps0;
	if(window.location.hostname == "www.energy-zone.com") apikey = maps1;
	if(window.location.hostname == "rd-nfr-cms71") apikey = maps2;
	if(window.location.hostname == "mainova.pinuts.de") apikey = maps3;
	
		
	document.write("<script src=\"http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAfIGpMZC3MM4FxKKNPhUGgRQKzLjeTDucmapv12DEWSVEnrFjCxRjrbPuBAnqRG7FpNWYcLbzubsLGA\" type=\"text/javascript\"></script>");
}


var handleurl = window.location.protocol + "//" + window.location.hostname + "/"; 



if (window.location.hostname == "mainova.pinuts.de") {
     handleurl = "http://mainova.pinuts.de/energyzone/";
}

var errorpage = handleurl +"fehler.jsp";	



/**
 * Login Formular.
 * 
 * 1: korrekt
 * 0: falsch
 */
var submitLoginForm = function() {

    var nickname = document.LoginForm.nickname.value;
    var password = document.LoginForm.password.value;
    var layer    = document.LoginForm.setLayer.value;
    
    new Ajax.Request(
            handleurl+'do_login.jsp?',          
            {           
                asynchronous:true,
                method:'post',
                postBody:'name=' + nickname + '&p=' + password, 
                onSuccess: function(t) {
                /* leerzeichen entfernen trim */
                while (t.responseText.substring(0,1) == ' ')
                {
                    t.responseText = t.responseText.substring(1, t.responseText.length);
                }
                while (t.responseText.substring(t.responseText.length-1, t.responseText.length) == ' ')
                {
                    t.responseText = t.responseText.substring(0,t.responseText.length-1);
                }
                
                if (t.responseText == "1") {
                    allelayeraus();
                    MM_showHideLayers(layer,'','show');
                    
                } else if (t.responseText == "0") {
                    document.getElementById('loginFehler2').style.display = "none";
                    document.getElementById('loginFehler1').style.display = "";
                
                } else if (t.responseText == "2") {
                    document.getElementById('loginFehler1').style.display = "none";
                    document.getElementById('loginFehler2').style.display = "";
                
                } else {
                    return;
                }       
                                    
            }                     
            }           
    );  
}


/**
 * Request Weiterempfehlen Formular.
 * 
 * 1: abgesendet
 * 0: nicht abgesendet
 */
var submitEmpfehlenForm = function() {

    var name = document.EmpfehlenForm.name.value;
    var email = document.EmpfehlenForm.email.value;
    var text = document.EmpfehlenForm.text.value;
    var copy = (document.EmpfehlenForm.copy.checked) ? "1" : "0";
    
    new Ajax.Request(
            handleurl+'do_weiterempfehlen.jsp',           
            {           
                asynchronous:true,
                method:'post',
                postBody:'name=' + name + '&email=' + email + '&text=' + text + '&copy=' + copy + '&seitentitel=' + seitentitel + '&teaser=' + teaser + '&seitenurl=' + seitenurl + '&category=' + kategorie,
                onSuccess: function(t) {
                /* leerzeichen entfernen trim */
                while (t.responseText.substring(0,1) == ' ')
                {
                    t.responseText = t.responseText.substring(1, t.responseText.length);
                }
        
                while (t.responseText.substring(t.responseText.length-1, t.responseText.length) == ' ')
                {
                    t.responseText = t.responseText.substring(0,t.responseText.length-1);
                }

                
                if (t.responseText == "1") {
                    /* Wenn das Serverscript den String "1" zurueckliefert -> erfolgreich */
                    allelayeraus();
                    MM_showHideLayers('dankeLayer','','show');
                    
                } else if (t.responseText == "0") {
                    /* Wenn das Serverscript "0" zurueckgibt -> Fehler */
                    //fixme
                    
                } else {
                    return false;
                }       
                                    
            }                     
            }           
    );  
}


var setAnswer = function(formname,id,txt) {
    document.forms[formname].aId.value = id;
    document.forms[formname].aTxt.value = txt;
}


/**
 * Request Gewinnspiel Formular.
 * 
 * 1: abgesendet
 * 0: nicht abgesendet
 * 2: schonmal dran teilgenommen
 */
var submitSpielForm = function() {

    //var qId  = document.spielForm.qId.value;
    //var qTxt = document.spielForm.qTxt.value;
    var aTxt = document.spielForm.aTxt.value;
    var sId  = document.spielForm.sId.value; 
    var copy = (document.spielForm.copy.checked) ? "1" : "0";
    
    var aId  = document.spielForm.aId.value;
    
    new Ajax.Request(
            handleurl+'do_gewinnspiel.jsp',           
            {           
                asynchronous:true,
                method:'post',
                postBody:'&aId=' + aId + '&aTxt=' + aTxt + '&sId=' + sId + '&copy=' + copy,
                onSuccess: function(t) {
                /* leerzeichen entfernen trim */
                while (t.responseText.substring(0,1) == ' ')
                {
                    t.responseText = t.responseText.substring(1, t.responseText.length);
                }
        
                while (t.responseText.substring(t.responseText.length-1, t.responseText.length) == ' ')
                {
                    t.responseText = t.responseText.substring(0,t.responseText.length-1);
                }

                
                if (t.responseText == "1") {
                    /* Wenn das Serverscript den String "1" zurueckliefert -> erfolgreich */
                    allelayeraus();
                    MM_showHideLayers('gewinnLayer','','show');
                    
                } else if (t.responseText == "0") {
                    /* Wenn das Serverscript "0" zurueckgibt -> Fehler */
                    //fixme
                    
                } else if (t.responseText == "2") {
                    document.getElementById('playedBefore').style.display = "";
                
                } else {
                    //return false;
                }       
                                    
            }                     
            }           
    );  
}


/**
 * Kontakt Formular.
 * 
 * 1: abgesendet
 * 0: nicht abgesendet
 */
var submitKontaktForm = function() {

    var name = encodeURIComponent(document.KontaktForm.name.value);
    var email = encodeURIComponent(document.KontaktForm.email.value);
    var text = encodeURIComponent(document.KontaktForm.text.value);
    
    new Ajax.Request(   
            handleurl+'do_kontakt.jsp',
            {           
                asynchronous:true,
                method:'post',
                postBody:'name=' + name + '&email=' + email + '&text=' + text,
                /*onFailure: function(resp)
                {
                    alert('Fehler:' + resp.statusText);
                },*/
                onSuccess: function(t)
                {
                
                /* leerzeichen entfernen trim */
                while (t.responseText.substring(0,1) == ' ')
                {
                    t.responseText = t.responseText.substring(1, t.responseText.length);
                }
        
                while (t.responseText.substring(t.responseText.length-1, t.responseText.length) == ' ')
                {
                    t.responseText = t.responseText.substring(0,t.responseText.length-1);
                }

                
                if (t.responseText == "1") {
                    /* Wenn das Serverscript den String "1" zurueckliefert -> erfolgreich */
                    allelayeraus();
                    MM_showHideLayers('dankeLayer','','show');
                    
                } else if (t.responseText == "0") {
                    /* Wenn das Serverscript "0" zurueckgibt -> Fehler */
                    //fixme
                    
                } else {
                    return;
                }       
                
                }                     
            }           
    );  
}


/**
 * Zeigt einen Layer an, wenn man eingeloggt ist, sonst LoginLayer.
 * 
 * 1: eingeloggt.
 * 0: nicht eingeloggt.
 */
function showLayer(id) {
    
    new Ajax.Request(   
                     handleurl+'do_isLoggedIn.jsp',           
                     {           
                         asynchronous:true,
                         method:'post',
                         onSuccess: function(t)
                         {
                         
                         /* leerzeichen entfernen trim */
                         while (t.responseText.substring(0,1) == ' ')
                         {
                             t.responseText = t.responseText.substring(1, t.responseText.length);
                         }
                 
                         while (t.responseText.substring(t.responseText.length-1, t.responseText.length) == ' ')
                         {
                             t.responseText = t.responseText.substring(0,t.responseText.length-1);
                         }

                         if (t.responseText == "1") {
                             /* Wenn das Serverscript den String "1" zurueckliefert -> erfolgreich */
                             MM_showHideLayers(id,'','show');
                             
                         } else if (t.responseText == "0") {
                             /* Wenn das Serverscript "0" zurueckgibt -> Fehler */
                             document.getElementById('setLayer').value = id;
                             MM_showHideLayers('loginLayer','','show');
                             
                         } else {
                             return;
                         }       
                         
                         }                     
                     }           
             );  
    
    
}


