/* 
 * Survey Popup 
 */
function getElementById(id)
{
   var object = null;

   if (document.layers) 
   {
      object = document.layers[id];
   }
   else if (document.all) 
   {
      object = document.all[id];
   }
   else if (document.getElementById) 
   {
      object = document.getElementById(id);
   }

   return object;
}

function showElement(id)
{
	var divBox = getElementById(id);

	divBox.style.display = "block";
}

function hideElement(id)
{
	var divBox = getElementById(id);

	divBox.style.display = "none";
}

function showSurveyPopup(host, surveyNo)
{
   var url= document.URL;

   var contextRoot = url.substr(7); // www.arburg.com/com/COM/de

   contextRoot = contextRoot.substr(contextRoot.indexOf('/') + 1);  // com/COM/de

   var urlRel = contextRoot;

   contextRoot = contextRoot.substr(0, contextRoot.indexOf('/')); // com

   contextRoot = '/' + contextRoot;

   var is_COM_DE = (urlRel === 'com/COM/de/' || urlRel === 'com/COM/de/index.jsp');
   var is_COM_EN = (urlRel === 'com/COM/en/' || urlRel === 'com/COM/en/index.jsp');

   
   if (is_COM_DE || is_COM_EN) 
   {
      var ShowEveryXVisitors = 5;
      var surveyRndNo = Math.floor(Math.random() * ShowEveryXVisitors);

      if (surveyRndNo > 0)
      {
         return false;
      }

      body = document.getElementsByTagName('body')[0];
      
      popup = document.createElement('div');
      popup.id = 'popupMask';
      
      content = document.createElement('div');
      content.id = 'popupContent';


      if (is_COM_DE) 
      {
         var surveyUrl = host + '/webapps/dcmtanfrage/SurveyServlet?UMFRAGE=' + surveyNo + '&SPRACHE=de';

         content.innerHTML = '' + 
         '<table cellspacing="0" cellpadding="0" width="100%">' + 
         '<tr>' + 
            '<td style="padding-left: 10px;"><img src="' + contextRoot + '/common/images/logo.gif" ></td>' + 
            '<td nowrap="nowrap" width="100%" align="right" style="padding-top: 20px; padding-right: 30px;"><nobr><a href="#" onclick="closeSurveyPopup();"><img src="' + contextRoot + '/common/images/close-popup.gif" alt="Schlie&szlig;en"/></a></nobr></td>' + 
         '</tr>' + 
         '<tr>' + 
            '<td colspan="2" align="center" style="padding-top: 40px; padding-left: 40px; padding-right: 40px;">' +
            '<div class="headline" style="text-align: left;">Ihre Meinung ist uns wichtig!</div><br/>' +
            '<div class="text">Bitte nehmen Sie sich kurz Zeit f&uuml;r eine Befragung zu unserem Webauftritt. ' + 
            'Sie helfen uns dabei, diesen in Ihrem Sinne weiter zu verbessern! <br/><br/>' +
            'Selbstverst&auml;ndlich behandeln wir Ihre Antworten streng vertraulich und v&ouml;llig anonym.<br/><br/>' +
            'Vielen Dank im Voraus f&uuml;r Ihre Unterst&uuml;tzung!</div> <br /><br />' +
            '<span style="cursor: pointer;" onclick="startSurvey(\'' + surveyUrl + '\');"><img src="' + contextRoot + '/common/images/start_survey_de.gif"></span>' +
            '</td>' + 
         '</tr>' + 
         '</table>';
      }
      else
      {
         var surveyUrl = host + '/webapps/dcmtanfrage/SurveyServlet?UMFRAGE=' + surveyNo + '&SPRACHE=en';

         content.innerHTML = '' + 
         '<table cellspacing="0" cellpadding="0" width="100%">' + 
         '<tr>' + 
            '<td style="padding-left: 10px;"><img src="' + contextRoot + '/common/images/logo.gif" ></td>' + 
            '<td nowrap="nowrap" width="100%" align="right" style="padding-top: 20px; padding-right: 30px;"><nobr><a href="#" onclick="closeSurveyPopup();"><img src="' + contextRoot + '/common/images/close-popup.gif" alt="Close"/></a></nobr></td>' + 
         '</tr>' + 
         '<tr>' + 
            '<td colspan="2" align="center" style="padding-top: 40px; padding-left: 40px; padding-right: 40px;">' +
            '<div class="headline" style="text-align: left;">Your opinion is important to us.</div><br/>' +
            '<div class="text">Please take a few minutes to complete this brief survey regarding our website. ' + 
            'In this way, you will help us to further improve the website - to your benefit! <br/><br/>' +
            'Your answers will, of course, be treated as strictly confidentially and will remain completely anonymous.<br/><br/>' +
            'Many thanks in advance for your support!</div> <br />' +
            '<span style="cursor: pointer;" onclick="startSurvey(\'' + surveyUrl + '\');"><img src="' + contextRoot + '/common/images/start_survey_en.gif"></span>' +
            '</td>' + 
         '</tr>' + 
         '</table>';
      }

 
      popup.appendChild(content);
      body.appendChild(popup);
      body.style.overflow = "hidden";
      
      showElement('popupMask');
   }
}

function startSurvey(url)
{
   closeSurveyPopup();
  
   var screenBreite = (screen.availWidth); 
   var screenHoehe = (screen.availHeight); 

   var screenMitteH = screenBreite/2;
   var screenMitteV = screenHoehe/2-100;

   posLeft = screenMitteH - 342;
   posTop = screenMitteV - 321;

   winpop = window.open(url,'w','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width=684,height=642,left=' + posLeft + ',top=' + posTop);
   winpop.focus();
}

function closeSurveyPopup()
{
   hideElement("popupMask");
   body.style.overflow = "auto";
}
