/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function parseTastings()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerTasting');
  //alert(tastingXSL);
  if (tastingXSL != null && el!=null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }

//var el = document.getElementById("TastingScroller");
//scroller = new jsScroller(el, 400, 200);
//scrollbar = new jsScrollbar (document.getElementById("TastingScrollbar-Container"), scroller, true, scrollbarEvent);


// el.innerHTML="";
}

function parseTastingAllEventShow()
{
  var xmlDoc = this.req.responseText;
  //alert(xmlDoc);
  var el = document.getElementById('LayerTastingShowAllEvent');
  el.innerHTML = xmlDoc;
}
function parseTastingAllEventShow2()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerTastingShowAllEvent');
  //alert(tastingXSL);

  if (tastingShowAllEventXSL != null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingShowAllEventXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingShowAllEventXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }
  el.style.visibility = "visible";
  
}

function parseTastingAllEventPromoShow()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerPromotionEvent');
  // alert(el);

  if (tastingShowAllEventPromoXSL != null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingShowAllEventPromoXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingShowAllEventPromoXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }
  el.style.visibility = "visible";
}
function parseTastingAllEventPromoShowAlone()
{
  var xmlDoc = this.req.responseText;
  var el = document.getElementById('LayerPromotionEvent');
  if (el != null)
  {
    el.innerHTML=xmlDoc;
  }
}

function parseTastingAllEventPromoShowAlone2()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerPromotionEvent');
  //alert(el);

  if (tastingShowAllEventPromoAloneXSL != null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingShowAllEventPromoAloneXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingShowAllEventPromoAloneXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }
  el.style.visibility = "visible";
}

function parseTastingAllEvent()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerTastingShowAll');
  //alert(tastingXSL);
  if (tastingShowAllXSL != null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingShowAllXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingShowAllXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }
  var selected = xmlDoc.getElementsByTagName("selected");
  for (i=0;i<selected.length;i++)
  {
    var eid = selected[i].getAttribute("eid");
    //  alert("eid:"+eid);
    var ttable = document.getElementById('TastingScroller-Container');
    if (ttable != null)
    {
      var currentIdx = -1;

      var trs = ttable.childNodes;
      //    alert(currentIdx);
      for(i=0 ; i < trs.length ; i++)
      {
        var row = trs[i];
        //      alert("nodeType:"+row.nodeType);
        if (row.nodeType == 1)
        {
          //       alert(row.getAttribute("event_id"));
          if (row.getAttribute("event_id") == eid)
          {
            currentIdx = i;
          }
        }
      }
      // alert(currentIdx);
      if (currentIdx == -1)
      {
        showTastingAllEvent(eid);
       
      }
      else
      {
        var selEl = trs[currentIdx];
        //alert(selEl);
        if (selEl != null)
        {
          // alert("event_id:"+selEl.getAttribute("id"));
          showTastingAllEvent(selEl.getAttribute("id"));
        }
      }
    }
  }

}

function parseTastingEvent()
{
  //alert(this.req.responseText);
  var xmlDoc = this.req.responseXML;
  var el = document.getElementById('LayerTastingShow');
  //alert(tastingXSL);
  if (tastingEventXSL != null)
  {
    if (window.ActiveXObject)
    {
      el.innerHTML = xmlDoc.transformNode(tastingEventXSL);
    // alert(el.innerHTML);
    }
    else
    {
      var xsltProcessor = new XSLTProcessor();
      xsltProcessor.importStylesheet(tastingEventXSL);
      var fragment = xsltProcessor.transformToFragment(xmlDoc,document);

      el.innerHTML='';
      el.appendChild(fragment);
    //  alert(el.innerHTML);

    }
  }

}

function parseTastingXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingXSL=  res;
  //  new net.ContentLoader('barreltasting/functions/getTasting.php?&date ='+new Date(),parseTastings);
  new net.ContentLoader('admin/functions/getPromotionTest.php?&date ='+new Date(),parseTastings);
}
function parseTastingEventXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingEventXSL=  res;
}

function parseTastingShowAllXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingShowAllXSL=  res;
}
function parseTastingShowAllEventXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingShowAllEventXSL=  res;
}
function parseTastingShowAllEventPromoXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingShowAllEventPromoXSL=  res;
}
function parseTastingShowAllEventPromoAloneXSL()
{
  var res = this.req.responseXML;
  // alert(this.req.responseText);
  tastingShowAllEventPromoAloneXSL=  res;
}

function showTastingAllEvent(idx)
{
  //  alert(idx);
  var el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    // var vis = el.style.visibility;
    el.style.left="434px";
    el.innerHTML="";
    el.style.visibility="visible";
    el.style.zIndex = "10";
  }
  //alert(idx.startsWith("event_")+"_"+idx);
  if (selectedTSmagning != null && selectedTSmagning.id.startsWith("event_") && selectedTSmagning.getAttribute("type")=="EVENT")
  {
    selectedTSmagning.style.background="white";
  }
  var tdEl= document.getElementById(idx);
  if (tdEl != null)
  {
    if (idx.startsWith("event_") && tdEl.getAttribute("type")=="EVENT")
    {
      tdEl.style.background="#CCCCCC";
    }
    new net.ContentLoader('barreltasting/functions/getTastingEvent2.php?eventid='+tdEl.getAttribute("event_id")+'&date ='+new Date(),parseTastingAllEventShow);

  }

  selectedTSmagning = tdEl;
}
function showPromoEvent(idx,alone)
{
  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="2";

  }
  //hideBlackShade();

  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="2";

  }
  el = document.getElementById("LayerPromotionEvent");
  if (el != null)
  {
    el.style.left="221px";
    var elheight=el.offsetHeight;
      el.innerHTML="<center><img class=\"va\" src=\"images/wait26trans.gif\" style=\"position:relative;top:"+((elheight/2)-30)+"px;\" /></center>";
      el.style.visibility="visible";
  }
  if (selectedTSmagning != null)
  {
    selectedTSmagning.style.background="white";
  }
  closeFunction = closeShowAll
    
  if (alone)
  {
    new net.ContentLoader('barreltasting/functions/getPromotionEvent2.php?eventid='+idx+'&date ='+new Date(),parseTastingAllEventPromoShowAlone);
  }
  else
  {
    new net.ContentLoader('barreltasting/functions/getPromotionEvent2.php?cf=closePromo&eventid='+idx+'&date ='+new Date(),parseTastingAllEventPromoShowAlone);
  }

  
  setBlackShade();

  selectedTSmagning = null;
  
  
}

function showTasting(idx)
{
  //new net.ContentLoader('barreltasting/functions/getTasting.php?&date ='+new Date(),parseTastingEvent);
  showAllTasting(idx);
  //showTastingAllEvent(idx);
  /*
  var el = document.getElementById("LayerTastingShow");
  if (el != null)
  {
    var vis = el.style.visibility;
    el.style.visibility="visible";

  }
   */
  if (selectedTSmagning != null)
  {
    if (idx.startsWith("event_"))
    {
      selectedTSmagning.style.background="white";
    }
  }
  /*
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="10";

  }
   */
  setBlackShade();
  if (selectedTSmagning != null)
  {
    if (idx.startsWith("event_"))
    {
      selectedTSmagning.style.background="white";
    }
  }
  
  var tdEl= document.getElementById(idx);
  if (tdEl != null && idx.startsWith("event_"))
  {
    tdEl.style.background="#CCCCCC";
  }

  selectedTSmagning = tdEl;
}

function closeTasting()
{
  var el = document.getElementById("LayerTastingShow");
  if (el != null)
  {
    var vis = el.style.visibility;
    el.style.visibility="hidden";

  }
  hideBlackShade();
  
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="1";

  }
  if (selectedTSmagning != null)
  {
    selectedTSmagning.style.background="white";
    selectedTSmagning = null;
  }
}

function closeShowAll()
{
  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    var vis = el.style.visibility;
    el.style.visibility="hidden";

  }
  hideBlackShade();
  
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="1";

  }
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    var vis = el.style.visibility;
    el.style.visibility="hidden";

  }
  el = document.getElementById("LayerPromotionEvent");
  if (el != null)
  {
    el.style.visibility="hidden";

  }
  el = document.getElementById("editPopups");
  if (el != null)
  {
    el.style.visibility="hidden";

  }
  el = document.getElementById("LayerForumAddEvent");
  if (el != null)
  {
    el.innerHTML="";
    el.style.visibility="hidden";


  }
}
function closePromo()
{
  
  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
  //hideBlackShade();

  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="10";

  }
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="1";

  }
  
  el = document.getElementById("LayerPromotionEvent");
  if (el != null)
  {
    el.style.visibility="hidden";

  }
  
}

function closePromoAlone()
{

  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
  hideBlackShade();

  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="10";

  }
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="1";

  }

  el = document.getElementById("LayerPromotionEvent");
  if (el != null)
  {
    el.style.visibility="hidden";

  }

}

function closeShowAllEvent()
{
        
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    el.style.visibility="hidden";

  }
}

function selectNextTastingShowAll(direction)
{
  //alert("selectNextTastingShowAll");
  if (selectedTSmagning != null)
  {

    //var children = document.getElementById('TastingScroller-Container').childNodes;
    //alert(children.length);

    var ttable = document.getElementById('TastingScroller-Container');
    if (ttable != null)
    {
      var currentIdx = -1;

      var trs = ttable.childNodes;
      for(i=0 ; i < trs.length ; i++)
      {
        var row = trs[i];
        if (row.nodeType == 1)
        {
          if (row.id == selectedTSmagning.id)
          {
            currentIdx = i;
          }
        }
      }
      if (currentIdx >= 0)
      {
        // alert("currentID:"+currentIdx)
        if (currentIdx ==0 && direction < 0)
        {
          this.showTastingAllEvent("event_1");
        }
        //else if (currentIdx ==1 && direction <0)
        //  {
        //  this.showTastingAllEvent("event_1");
        // }
        else
        {
          var selEl = trs[currentIdx+direction];
          while (selEl != null && selEl.nodeType != 1)
          {
            currentIdx+=direction;
            selEl = trs[currentIdx+direction];
          }
          if (selEl != null)
          {
            //alert(selEl.id+"_"+selEl.getAttribute("event_id"));
            if (selEl.getAttribute("event_id") != null)
            {
              this.showTastingAllEvent(selEl.id);
            }
            else
            {
              this.showTastingAllEvent("event_1");
            }
          }
        }
      }
      else if (currentIdx == -1 && direction>0)
      {
        var selID = selectedTSmagning.id;
        var iCount = selID.substring(selID.indexOf("_")+1);
        //alert("event_"+(parseInt(iCount)+1));
        if (parseInt(iCount) > ttable.childNodes.length)
        {
          this.showTastingAllEvent("event_1");
        }
        else{
          this.showTastingAllEvent("event_"+(parseInt(iCount)+1));
        }
      }
      
      else if (currentIdx == -1 && direction < 0)
      {
        this.showTastingAllEvent("event_1");
      }
      
    }
  }
}
function selectNextTasting(direction)
{
  if (selectedTSmagning != null)
  {

    var ttable = document.getElementById("tastingtable");
    if (ttable != null)
    {
      var currentIdx = 0;

      var trs = ttable.getElementsByTagName("tr");
      for(i=0 ; i < trs.length ; i++)
      {
        var row = trs[i];
        if (row.id == selectedTSmagning.id)
        {
          currentIdx = i;
        }
      }
      var selEl = trs[currentIdx+direction];
      if (selEl != null)
      {
        this.showTasting(selEl.id);
        //selEl.scrollIntoView();
        var elll = document.getElementById("divts_2");
        if (elll != null)
        {
      // alert(elll.style.top);
      }
      }
    }
  }
}
function showAllLoaded()
{
  alert("showAllLoaded");
}

function showAllTastingNext(startoffset,maxevents)
{
  //alert(startoffset);
  if (startoffset >= 0 && startoffset <= maxevents)
  {
    new net.ContentLoader('barreltasting/functions/getTastingOrder.php?startoffset='+startoffset+'&date ='+new Date(),parseTastingAllEvent);
  }
}

function showAllTasting(idx)
{
  //  alert(idx);

  closeFunction =  closeShowAll;
  if (idx)
  {
    // url,onload,onerror,method,params,contentType,notify
    //  alert("calling notify");
    new net.ContentLoader('barreltasting/functions/getTastingOrder.php?eid='+idx+'&date ='+new Date(),parseTastingAllEvent);
  }
  else
  {
    new net.ContentLoader('barreltasting/functions/getTastingOrder.php?&date ='+new Date(),parseTastingAllEvent);
  }

  var el = document.getElementById("LayerTastingShowAll");
  //alert(el);
  if (el != null)
  {
    var vis = el.style.visibility;
    //if (vis == "hidden")
    {
      var elheight=el.offsetHeight;
      el.innerHTML="<center><img class=\"va\" src=\"images/wait26trans.gif\" style=\"position:relative;top:"+((elheight/2)-30)+"px;\" /></center>";
      
      el.style.visibility="visible";
      el.style.zIndex = "10";
    }
  //else
  // {
  //  el.style.visibility="hidden";
  //}
  }
  /*
  el = document.getElementById("LayerTasting");
  if (el != null)
  {
    el.style.zIndex="10";

  }
   */
  setBlackShade();
  
}

function parseCompanyCard2()
{
  var xmlDoc = this.req.responseText;
  //alert(xmlDoc);
  //alert(xmlDoc.xml);
  var el = document.getElementById('comp_card');
  //alert(el);
  if (el != null)
  {
    el.innerHTML = xmlDoc;
  }
  var hh = el.offsetHeight;
  var tt = document.getElementById("ToolTip3");
  if (tt != null)
  {
    var ttTop = tt.style.top;
    if (ttTop.indexOf("px")>0)
    {
      ttTop = ttTop.substring(0,ttTop.indexOf("px"));
      ttTop = parseInt(ttTop);
    }
    var ttt = (ttTop-hh-32);
    if (ttt < 2)
    {
      ttt = 2;
    }
    tt.style.top=(ttt)+"px";

  }
  tt.style.visibility="visible";
}

function parseCompanyCard()
{

  var xmlDoc = this.req.responseXML;
  //alert(xmlDoc.xml);
  var el = document.getElementById('comp_card');
  //alert(tastingXSL);
  if (el != null)
  {
    var companies = xmlDoc.getElementsByTagName("company");
    var s = "";
    for(i=0; i<companies.length; i++)
    {
      var c = companies[i];

      s += "<table class=\"eightpoint\" width=\"200px\" style=\"margin:0px 0px 0px 0px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
      s+= "     <tr style=\"margin 0 0 0 0\">";
      s+= "          <td width=\"200px\" style=\"overflow:hidden;width:200px;height:40px;\">";
      var logo  = c.getAttribute("logo");
      if (logo != null && logo != '')
      {
        //  s+= "            <img src=\"images/"+c.getAttribute("logo")+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        var istmp = c.getAttribute("table");
        
        if (istmp != null && istmp != '')
        {
          s+= "            <img src=\"admin/functions/getCreatorLogo.php?usetmp=true&user_id="+c.getAttribute("comp_id")+"&date="+new Date()+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        }
        else
        {
          s+= "            <img src=\"admin/functions/getCreatorLogo.php?user_id="+c.getAttribute("comp_id")+"&date="+new Date()+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        }
      }
      s+= "          </td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("comp")+"</td>";
      s+= "        </tr>";
      if (c.getAttribute("dep")!='')
      {
        s+= "        <tr>";
        s+= "          <td>"+c.getAttribute("dep")+"</td>";
        s+= "        </tr>";
      }
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("address")+"</td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+(c.getAttribute("comppost")=='0'?'':c.getAttribute("comppost"))+" "+c.getAttribute("town")+"</td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("web")+"</td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("mail")+"</td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("telephone")+"</td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td height=\"16px\"></td>";
      s+= "        </tr>";
      s+= "        <tr>";
      s+= "          <td>"+c.getAttribute("description")+"</td>";
      s+= "        </tr>";

      var pic  = c.getAttribute("pic");
      if (pic != null && pic != '')
      {
        s+= "        <tr>";
        s+= "          <td width=\"200px\" style=\"overflow:hidden;width:200px;height:40px;\">";
        //  s+= "            <img src=\"images/"+c.getAttribute("logo")+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        var istmp = c.getAttribute("table");

        if (istmp != null && istmp != '')
        {
          s+= "            <img src=\"admin/functions/getCreatorPicture.php?usetmp=true&user_id="+c.getAttribute("comp_id")+"&date="+new Date()+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        }
        else
        {
          s+= "            <img src=\"admin/functions/getCreatorPicture.php?user_id="+c.getAttribute("comp_id")+"&date="+new Date()+"\" width=\"125px\" onclick=\"\" border=\"0\"/>";
        }
        s+= "        </td>";
        s+= "        </tr>";
        s+= "        <tr>";
        s+= "          <td class=\"sixpointeq\">"+c.getAttribute("pictext")+"</td>";
        s+= "        </tr>";
      }
      
      s+= "      </table>";
    }
    el.innerHTML = s;
  }
  var hh = el.offsetHeight;
  var tt = document.getElementById("ToolTip3");
  if (tt != null)
  {
    var ttTop = tt.style.top;
    if (ttTop.indexOf("px")>0)
    {
      ttTop = ttTop.substring(0,ttTop.indexOf("px"));
      ttTop = parseInt(ttTop);
    }
    var ttt = (ttTop-hh-32);
    if (ttt < 2)
    {
      ttt = 2;
    }
    tt.style.top=(ttt)+"px";
  }
  /*
  var bottom = ToolTip.offsetTop -100 + ToolTip.offsetHeight;
        //alert(y+"_"+ToolTip.offsetHeight+"_"+screen.availHeight);
        if (ToolTip.offsetTop > 500)
        {
          ToolTip.style.top=(ToolTip.offsetTop-ToolTip.offsetHeight);
        }
        else
        {
          ToolTip.style.top=(ToolTip.offsetTop-100);
        }
  */
  tt.style.visibility="visible";
}

//{@event_id},'{@comp}',{@comppost},'{@description}'
function mailTasting(id,comp,post,etype,etid)
{
  this.sendBackofBlack();
  // alert(id+"_"+comp+"_"+post+"_"+etype+"_"+etid);
  var el = document.getElementById("editPopups");
  // alert(encodeURIComponent('Tøndesmagning,'+comp+','+post));
  var cmp = "T%C3%B8ndesmagning";
  if (etype != null)
  {
    cmp = etype;
  }
  if (post==0)
  {
    post = '';
  }
 // alert("mail/mail.php?eid="+id+"&etid="+etid+"&comp="+cmp+encodeURIComponent(','+comp+','+post)+"&post="+post+"&closefunction=closeEmailWindow"+","+"editPopups"+","+"");
  loadWholePage("mail/mail.php?eid="+id+"&etid="+etid+"&comp="+cmp+encodeURIComponent(','+comp+','+post)+"&post="+post+"&closefunction=closeEmailWindow","editPopups","");
  var w = 316;
  var h = 340;
  el.style.width=(w)+"px";
  el.style.height=(h)+"px";
  //el.style.border="1px solid #8CC63F";
  el.className ="thinborder";
  // alert(screen.height);
  el.style.top = (screen.availHeight/2-(h/2))+"px";
  el.style.left = (screen.width/2-(w/2))+"px";
  el.style.visibility="visible";
//el.innerHTML = mail.innerHTML;
}

function mailCalendarTasting(id,comp,post,etype,etid)
{
  this.sendBackofBlack();
  //alert(id+"_"+comp+"_"+post+"_"+description);
  var el = document.getElementById("editPopups");
  var cmp = "T%C3%B8ndesmagning";
  if (etype != null)
  {
    cmp = etype;
  }
  // alert(encodeURIComponent('Tøndesmagning,'+comp+','+post));
  loadWholePage("mail/mailCalendar.php?eid="+id+"&etid="+etid+"&comp="+cmp+encodeURIComponent(','+comp+','+post)+"&post="+post+"&company_name="+comp+"&closefunction=closeEmailWindow","editPopups","");
  var w = 316;
  var h = 340;
  el.style.width=(w)+"px";
  el.style.height=(h)+"px";
  //el.style.border="1px solid #8CC63F";
  el.className ="thinborder";
  // alert(screen.height);
  el.style.top = (screen.availHeight/2-(h/2))+"px";
  el.style.left = (screen.width/2-(w/2))+"px";
  el.style.visibility="visible";
//el.innerHTML = mail.innerHTML;
}

function closeEmailWindow()
{
  this.sendFrontofBlack();
  var el = document.getElementById("editPopups");
  if (el != null)
  {
    el.style.visibility = "hidden";
  }
}


function createXHR()
{
  var request = false;
  try {
    request = new ActiveXObject('Msxml2.XMLHTTP');
  }
  catch (err2) {
    try {
      request = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (err3) {
      try {
        request = new XMLHttpRequest();
      }
      catch (err1)
      {
        request = false;
      }
    }
  }
  return request;
}

function loadWholePage(url,storage,displayed)
{
 // alert(url+","+storage+","+displayed);
  var y = document.getElementById(storage);
  var x = document.getElementById(storage);
  loadHTML(url, "processHTML", x, y);
}

function loadHTML(url, fun, storage, param)
{
 // alert(url+"_"+ fun+"_"+storage+"_"+param);
  var xhr = createXHR();
  xhr.onreadystatechange=function()
  {
    if(xhr.readyState == 4)
    {
    //if(xhr.status == 200)
    {
      storage.innerHTML = xhr.responseText;
    //fun(storage, param);
    }
    }
  };

  xhr.open("GET", url , true);
  xhr.send(null);

}

function textfieldFocus(div)
{
  div.style.color="black";
  if (div.value == div.getAttribute("emptytext"))
  {
    div.value="";
  }
}
function textfieldUnFocus(div)
{
  var currentText = div.value;
  try{
    if (trim(currentText) == '')
    {
      div.style.color="#A7A9AC";
      var text = div.getAttribute("emptytext");
      div.value=""+text;
    }
  }catch(err){}
}
function sendBackofBlack()
{
  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="1";

  }
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="1";

  }
}

function sendFrontofBlack()
{
  var el = document.getElementById("LayerTastingShowAll");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
  el = document.getElementById("LayerTastingShowAllEvent");
  if (el != null)
  {
    //var vis = el.style.visibility;
    //el.style.visibility="hidden";
    el.style.zIndex="10";

  }
}

//function printSpecial(id,comp,post,desc,logo,comp,address,web,jpg,valid_to,eType,etext)
function printSpecial(id,eType,etid)
{
  //alert(id+"_"+eType+"_"+etid);
  if (etid == null)
  {
    etid = -1;
  }
  //  new net.ContentLoader('print/print.php?valid_to='+valid_to+'&event_type='+encodeURIComponent(eType)+'&eid='+id+'&desc='+encodeURIComponent(desc)+'&logo='+logo+'&comp='+encodeURIComponent(comp)+'&town='+encodeURIComponent(address)+'&web='+encodeURIComponent(web)+'&jpg='+encodeURIComponent(jpg)+'&extra_text='+encodeURIComponent(etext)+'&date ='+new Date(),parsePrintSpecial);
  new net.ContentLoader('print/functions/print.php?eid='+id+'&etid='+etid+'&event_type='+encodeURIComponent(eType)+'&date ='+new Date(),parsePrintSpecial);

}
function sendAppointment(id,comp,post,desc,logo,comp,address,web,jpg)
{
  //alert(id+"_"+comp+"_"+post+"_"+desc+"_"+logo);
  new net.ContentLoader('mail/printCalendar.php?desc='+encodeURIComponent(desc)+'&logo='+logo+'&comp='+encodeURIComponent(comp)+'&town='+encodeURIComponent(address)+'&web='+encodeURIComponent(web)+'&jpg='+encodeURIComponent(jpg)+'&date ='+new Date(),parseMailCalendar);

}

function parsePrintSpecial()
{
//alert("parsePrintSpecial");
//if (document.getElementById != null)
{
  var html = '<HTML>\n<HEAD>\n';

  //		if (document.getElementsByTagName != null)
  html+="<link rel=\"stylesheet\" type=\"text/css\" href=\"css/aov.css\"/>\n";
  {
    var headTags = document.getElementsByTagName("head");
    if (headTags.length > 0)
      html += headTags[0].innerHTML;
  }

  html += '\n</HE' + 'AD>\n<BODY>\n';
        
  html+= this.req.responseText;
  html += '\n</BO' + 'DY>\n</HT' + 'ML>';

  var printWin = window.open("","printSpecial");
  printWin.document.open();
  printWin.document.write(html);
  printWin.document.close();
//if (gAutoPrint)
//	printWin.print();
}
/*
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
   */
}

function parseMailCalendar()
{
//alert("parsePrintSpecial");
//if (document.getElementById != null)
{
  var html = '<HTML>\n<HEAD>\n';

  //		if (document.getElementsByTagName != null)
  {
    var headTags = document.getElementsByTagName("head");
    if (headTags.length > 0)
      html += headTags[0].innerHTML;
  }

  html += '\n</HE' + 'AD>\n<BODY>\n';

  html+= this.req.responseText;
  html += '\n</BO' + 'DY>\n</HT' + 'ML>';

  var printWin = window.open("","printSpecial");
  printWin.document.open();
  printWin.document.write(html);
  printWin.document.close();
//if (gAutoPrint)
//	printWin.print();
}
/*
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
   */
}




