﻿function sendToFriend(id,width,height) {
  /// <summary>This function will open a Dynamicweb "Send to friend" window.</summary>
  /// <returns type="Void" />
  /// <param name="id" type="String">optional: The Page ID. If no ID is specified it will look at the ID of the BODY tag. Should be "page<!--@Global:Page.ID-->".</param>
  /// <param name="width" type="String">optional: The width of the sendToFriend window. Default: 322</param>
  /// <param name="height" type="String">optional: The height of the sendToFriend window. Default: 250</param>
  // STH: 2011-10-04 Bruger nu standard
  if (jQuery('#sendToFriendHidden a').length>0) {
    jQuery('#sendToFriendHidden a').trigger('click');
  } else {
    var sCurrentLocation=encodeURI(document.location.href);
    var sID=(typeof id!='undefined')?id.toString():parseInt(document.body.id.replace('page','')).toString();
    if(sID!='NaN') {
      var sSendToFriend='/Admin/Public/SendToFriend.aspx?ID='+sID+'&M=SendFriend&url='+sCurrentLocation;
      var sWidth=(typeof width!='undefined')?width:322;
      var sHeight=(typeof height!='undefined')?height:250;
      window.open(sSendToFriend,'sendToFriend','width='+sWidth+',height='+sHeight);
    } else {
      alert('sendToFriend():\nYou need to specify page ID');
    }
  }
}

function printUsingLayoutfile(layoutfile) {
  /// <summary>This function will open window which will use specified layoutfile, after that it will do a window.print().</summary>
  /// <returns type="Void" />
  /// <param name="layoutfile" type="String">optional: The template name relative to "/Templates/Designs". If none is specified no layouttemplate replacment will occur, current layout will be used.</param>
  var sCurrentLocation=document.location.href+'';
  var sID=(typeof id!='undefined')?id.toString():parseInt(document.body.id.replace('page','')).toString();
  var sLayoutFile='';
  if(arguments.length==1) {
    sLayoutFile=((sCurrentLocation.indexOf('?')> -1)?'&':'?')+'LayoutTemplate=Designs/'+layoutfile;
  }
  bReadyToPrint=false;
  var oWin=window.open(sCurrentLocation+sLayoutFile,'printWindow');
  window.setTimeout(function () {
    oWin.print();
  },2000);
}



function extranetLogout() {
  /// <summary>Logs the current extranet user out</summary>
  document.location='http://'+document.location.host+'/admin/public/extranetlogoff.aspx';
}

jQuery(function() {
  // dropdown - f.eks. til vidensarkiv
  var o = jQuery('.sitemapDropdown');
  // STH: 2011-09-27 Hvis siden indeholder en sitemapDropdown gør efterfølgende
  if (o.length>0) {
    var i = jQuery('<div class="sitemapDropdownReplacement"></div>');
    var h = o.height();
    i.css({'height':h+'px',});
    var oVidensArkiv = jQuery(i);
    var oParent = o.parent();
  
    oParent.prepend(oVidensArkiv);

    var p = o.offset();
    if (p!=null) {
      jQuery('body').append(o.css({'top':(p.top-h)+'px','left':p.left+'px','z-index':'10', 'position':'absolute'}))
    }
    o.data('position', {'l':p.left, 'offset':document.body.offsetWidth});
    i.addClass('fullwidth');
    // Page title
    jQuery('#content').prepend(jQuery('.mainH1'));
    window.setInterval(vidensarkivPosition, 10);
  }
})

function vidensarkivPosition() {
  var i = jQuery('.sitemapDropdown');
  var oData = i.data('position');
  var iDiff = document.body.offsetWidth-oData.offset;
  var iOriginalLeft = oData.l;
  var iOriginalOffset = oData.offset;
  i.css('left', iOriginalLeft+(iDiff/2)+'px');
  //if (typeof console !='undefined') console.log(document.body.offsetWidth+' '+'left'+(oData.l)+'px'+' '+'offset'+(oData.offset)+'px')
}
