var mrtimeoffset;
var mrclocktimeout;

var MR_CLOCKREFRESHTIME=500;     //in millis
var MR_PREFIX="Time Vienna: ";   // what to show in front of clock
var MR_DIV_ID="mrclock";  // constant, leading to div-container 
var MR_AJAXURL="/fileadmin/clock/clocksrv.php";  // constant, leading to div-container 
var mrtimeoffset=0;

function ajaxread() 
{ 
  var ajaxread; 
  try { ajaxread=new XMLHttpRequest(); } 
  catch (e) { 
     try { ajaxread=new ActiveXObject("Msxml2.XMLHTTP"); } 
            catch (e) { 
               try { ajaxread=new ActiveXObject("Microsoft.XMLHTTP"); } 
               catch (e) {return false;} 
            } 
         } 
         
         ajaxread.onreadystatechange=function() 
  { 
     if(ajaxread.readyState==4) { 
            var servertime=new Date(ajaxread.responseText);
         mrtimeoffset=new Date().getTime()-servertime.getTime()-500;
         displaytime();
             } 
          }
           
  ajaxread.open("GET",MR_AJAXURL,true); //the name of the file that needs to be inserted into the division in this case its clock.php
   ajaxread.send(null); 

} 





function displaytime(){


  var t=new Date().getTime()-mrtimeoffset;
  var realtime=new Date(t);
  
  document.getElementById(MR_DIV_ID).innerHTML=  MR_PREFIX+
                                      realtime.getHours()+":"+
                                      leadzero(realtime.getMinutes())+":"+
                                      leadzero(realtime.getSeconds());

  mrclocktimeout=setTimeout("displaytime()",MR_CLOCKREFRESHTIME);
}
  

  
function leadzero(s) {
  if (s<10) { return "0"+s;} else {
  return s;
  }
}  
  

/*
window.onload=function(){
        ajaxread();
  
      
    
}
window.onunload=function(){
  clearTimeout(mrclocktimeout);
}
   
*/





/***************************/

﻿function InfoShow(name) {

  layer=document.getElementById(name);  

  if(layer.style.display == 'block')  {
      layer.style.display = '';
   } else {
    layer.style.display = 'block';
   }

}


function fauxhover(fauxlink,color) {
  fauxlink.style.color=color;
}

function cursorhand() {
   try {
     document.body.style.cursor='pointer';
  } catch (e){
     document.body.style.cursor='hand';
  }
}

function cursornormal() {
  document.body.style.cursor='default';  
}



/***************************/

$(document).ready(function() { 
   /*     ajaxread();*/
  
        initForm();
        
        $('.frompage').val(document.URL);
        
       
        $('.anfrageLink').click(function() { 
          
       
      
          $('#bodyright').block({
/*          $.blockUI({ */
                        message: $('#maildialog') ,
                        css: {cursor:'normal',  width: '650px',height:'500px',
                          top:'0px',left:'0px', textAlign:'left',padding: '0px', margin:'0px',
                          border:'none',backgroundColor:'#312C2A'},
                        fadeOut:1000
                      });
                      
           
       
        });         
    
        $('#submit').click(function() {
            
            focusAll();
          
            if (validateFormOnSubmit($('#formMail'))) {
             
        var datastr = "name=" + encodeURIComponent($("#mailName").val())
                    + "&vorname=" + encodeURIComponent($("#mailVorname").val())
                    + "&titel="+ encodeURIComponent($("#mailTitel").val())
                    + "&email="+ encodeURIComponent($("#mailEmail").val())
                    + "&nachricht="+ encodeURIComponent($("#mailNachricht").val())
                    + "&telefon="+ encodeURIComponent($("#mailTelefon").val())
                    /*+ "&anrede="+ encodeURIComponent($("input[name='mailAnrede']:checked").val())*/
                    + "&mann="+ encodeURIComponent($("input[name='mailAnredeMann']:checked").val())
                    + "&frau="+ encodeURIComponent($("input[name='mailAnredeFrau']:checked").val())
                    + "&sprache="+ encodeURIComponent($("#mailSprache").val())
                    + "&adresse="+ encodeURIComponent($("#mailAdresse").val())
                    + "&frompage="+ encodeURIComponent(document.URL.toString())
                    + "&nlemail="+ encodeURIComponent($("input[name='aboMail']:checked").val())
                    + "&nlpost="+ encodeURIComponent($("input[name='aboPost']:checked").val())
                    + "&nlemailpost="+ encodeURIComponent($("input[name='aboMailPost']:checked").val())
                    + "&anfrageart="+encodeURIComponent($("select[name='Anfrageart'] option:selected").text())
                    ;
                  
        
         
         
         $.blockUI({ message: '<p>Mail wird gesendet...</p><p>Mail is being transmitted...</p>' ,
                        css: {width: '500px', top:'50px',left:'50px', textAlign:'left',padding:'20px'},
                        fadeOut:1000
                      }); 
                setTimeout($.unblockUI, 4000);
               
                $.ajax({ 
                   url: '/fileadmin/mail/mail.php', 
                        type:'GET',
               data: datastr,  
                         success: function (reqCode) {
                          if (reqCode!="ok") {
                            alert("**"+reqCode+"An error happened while sending the mail, please try later again!");
                          }
                       }
                });
                

            }
      blurAll();
            return false;
         }); 
 
        $('#cancel').click(function() { 
            $('#bodyright').unblock();
          /* $.unblockUI(); */
            return false; 
        }); 
  
  try {
         $('#mrclock').wagnerClock({
          /*width: 90,*/
          timezoneTitle: 'VIENNA',
       /*timezoneOffset: 1,*/
          background: false
          });
  } catch(e) {}
        
       $(".colorboxIframe").colorbox({
                 iframe:true, 
                 innerWidth:728, 
                 innerHeight:570,
         opacity:0.4
        });
  
    }); 
          
     function initForm() {
            var mailform= $('#maildialog').detach();
            mailform.appendTo('#bodyright');
      blurAll();
     }
     
     function blurAll() {
        fBlur(document.getElementById("mailEmail"));
   fBlur(document.getElementById("mailNachricht"));
   fBlur(document.getElementById("mailTitel"));
   fBlur(document.getElementById("mailVorname"));
   fBlur(document.getElementById("mailName"));
   fBlur(document.getElementById("mailTelefon"));
       fBlur(document.getElementById("mailAdresse"));
     }
     
     function focusAll() {
        fFocus(document.getElementById("mailEmail"));
   fFocus(document.getElementById("mailNachricht"));
   fFocus(document.getElementById("mailTitel"));
   fFocus(document.getElementById("mailVorname"));
   fFocus(document.getElementById("mailName"));
   fFocus(document.getElementById("mailTelefon"));
       fFocus(document.getElementById("mailAdresse"));
     }
