/* ===========================================================*/
/* Copyright (c) 2010 by SDN AG, CH-8912 Obfelden Switzerland */
/* -----------------------------------------------------------*/
/* Project : easyLEARN skills4u                               */
/* -----------------------------------------------------------*/
/* $Id: kntools.js,v 1.22 2010/06/08 13:54:56 MWE Exp $  */
/* ============================================================*/
/*
History
=======
$Log: kntools.js,v $
Revision 1.22  2010/06/08 13:54:56  MWE
*** empty log message ***

Revision 1.21  2009/11/30 12:41:23  MWE
*** empty log message ***

Revision 1.20  2009/10/28 13:03:27  MWE
*** empty log message ***

Revision 1.19  2008/06/12 14:19:39  MWE
*** empty log message ***

Revision 1.18  2008/06/10 15:38:05  MWE
*** empty log message ***

Revision 1.17  2008/02/08 08:21:24  MWE
Neue Funtionen DoZusatzeintrag/DoKeyWordHelper()

Revision 1.16  2007/08/14 08:45:07  MWE
CountClick(): IFRAME iclickframe erzeugen im aktuellen Dokument falls er noch nicht existiert

Revision 1.15  2007/04/13 09:59:31  MWE
Release 4.4

Revision 1.14  2007/01/25 15:56:00  MWE
*** empty log message ***

Revision 1.13  2006/10/23 07:29:25  MWE
Bildschirmgr�sse nicht mehr weitergeben bei Snacks. Diese wird seit V 4.3 vom Snackfenster gemacht.

Revision 1.12  2006/09/15 12:35:46  MWE
Release 4.3

Revision 1.11  2006/05/03 11:58:58  MWE
Titel vor dem Aufruf von swfplayer.php mit escape() vorbereiten

Revision 1.10  2005/10/12 14:43:27  MWE
Bei DoEntry auf javascript-Funktionen untersuchen und entsprechend behandeln

Revision 1.9  2005/04/15 09:50:42  MWE
Release 4.0

Revision 1.8  2004/11/03 13:06:34  MWE
Release 3.1

Revision 1.7  2004/10/06 06:49:32  MWE
StartPlayer/StartPlayerNewDoc: Parameter WMPSkin= nur bei IE und MP 7

Revision 1.6  2004/07/12 15:09:18  MWE
Release 2.6

Revision 1.5  2004/03/23 12:04:18  MWE
Release 2.4

Revision 1.4  2004/02/13 15:31:41  MWE
Release 2.2

Revision 1.3  2004/02/13 15:13:00  MWE
Release 2.2

Revision 1.2  2004/01/26 10:30:27  MWE
Release 2.1/2

Revision 1.1  2003/12/03 15:51:35  MWE
KnowledgePortal 2.0, update 2

Revision 1.2  2003/12/03 13:58:57  MWE
KnowledgePortal 2.0, update 2

Revision 1.1  2003/12/01 12:38:22  MWE
KnowledgePortal 2.0



*/


var defaultBandwidth = 2;

var ie4up = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
var elposwfplay = null;
var temporaryplayerwin = null;
var popupblockerwarning='Popup Blocker Active!\n\nDeutsch: Der Popup-Blocker des Browsers hat das Oeffnen eines neuen Fensters verhindert. Oeffnen Sie das Fenster manuell in dem Sie auf den Link klicken.\n\nEnglish: The Popup blocker prevents a new window. Click the link to open the window manually.';

function GetSkills4uSiteId()
{
    if (document.gSkills4uSiteID)
      return document.gSkills4uSiteID;

  if (parent.gSkills4uSiteID)
     return parent.gSkills4uSiteID;
   if (top.gSkills4uSiteID)
     return top.gSkills4uSiteID;
   return "default";
}

function PopubBlockerInfo(amsg)
{
	popupblockerwarning=amsg;
}

function knuPopupBlocked()
{
  var isie7 = false;	
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //test for MSIE x.x;
  {
	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
    if (ieversion>=7)
      isie7 = true;
  }
  if (!isie7)
    alert(popupblockerwarning);
}
function CountClick(pageid)
{
  var zeit = new Date();
  var msec = zeit.getMilliseconds();
  if (document.getElementById)
  {
  	var iframe = document.getElementById("iclickframe");
  	if (!iframe || iframe == "undefined" || iframe == null)
  	{
  	  var iframe = document.createElement("iframe");
  	  iframe.id = "iclickframe";
  	  iframe.width = "1px";
  	  iframe.height = "1px";
  	  iframe.src = "knclicker.php?id=" + pageid + "&ts=" + msec + "";
  	  iframe.zIndex = 1;
  	  var xnodes = document.getElementsByTagName("body")[0];
  	  xnodes.appendChild(iframe);
  	}
  	else
      iframe.src = "knclicker.php?id=" + pageid + "&ts=" + msec + "";
  }
  else
  {
    if (ie4up)
    {
      document.all.iclickframe.src = "knclicker.php?id=" + pageid + "&ts=" + msec + "";
    }
    else
    {
      document.iclickframe.src = "knclicker.php?id=" + pageid + "&ts=" + msec + "";
    }
  }

}

function DoEntry(pageid,url)
{
 var aurl = url + "";
 if (aurl.substring(0,11) == "javascript:")
 {
   var jsurl2 = aurl.replace(/~~/g,"'");
   eval(jsurl2);
   setTimeout("CountClick(" +pageid+")",1000);
 }
 else
 {
   var ewnhndl = window.open(url);
   if (!ewnhndl)
   {
   	if (aurl.substring(0,7) != 'mailto:')
   	  knuPopupBlocked();
   }
   else
     ewnhndl.focus();
   setTimeout("CountClick(" +pageid+")",1000);
 }
}

function DoGrain(pageid)
{

  var alpha = "abcdefghijklmnopqrstuvwxyz_";
  var url = "kngrainstart.html?pageid=" + pageid;
  var s = GetSkills4uSiteId() + "grain" + pageid + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  out += "" + pageid + "";
  winhndl = window.open(url, out,'left=10,top=10,width=640,height=480,status=yes,resizable=yes');
  if (!winhndl)
  {
	knuPopupBlocked();
  }
  else
  {
    winhndl.focus();
  }
  setTimeout("CountClick(" +pageid+")",1000);
}

function DoSnack(pageid)
{

  var alpha = "abcdefghijklmnopqrstuvwxyz_";
  var url = "lwplayer.php?pageid=" + pageid;
  var s = GetSkills4uSiteId() + "snack" + pageid + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  out += "" + pageid + "";
  winhndl = window.open(url, out,'left=10,top=10,width=640,height=480,status=yes,resizable=yes');
  if (!winhndl)
  {
	knuPopupBlocked();
  }
  else
  {
    winhndl.focus();
  }
  setTimeout("CountClick(" +pageid+")",1000);
}

function DoClip(pageid,aClip)
{
  startPlayerNewDoc(aClip) ;
  setTimeout("CountClick(" +pageid+")",1000);
}

function DoSWF(pageid,url,awidth,aheight,atitle,aflag)
{
  DoSWFPlay(pageid,url,awidth,aheight,atitle,aflag)
  setTimeout("CountClick(" +pageid+")",1000);
}

function DoSWFPlay(pageid,url,awidth,aheight,atitle,aflag)
{
  if (aheight == 0)
    aheight=600;
  if (awidth == 0)
   awidth = 800;
  var winwidth = awidth;
  var winheight= aheight;

  var s = aflag;
  var ipos = s.indexOf("controller=");
  if (ipos >= 0)
  {
  	var l = s.substring(ipos+11);
  	var ipos2 = l.indexOf(";");
  	var t = 0;
  	if (ipos2 >=0)
  	{
  	  t = l.substring(0,ipos2);
   	}
   	else
   	  t = l;
    if (t == 1)
    {                   // Controller=1
      winheight = aheight+17;
  	}
  }

  var leftpos = Math.round((screen.availWidth /2) - (winwidth/2));
  var toppos = Math.round((screen.availHeight /2) - (winheight/2)) -20;
  if (leftpos < 0) leftpos = 0;
  if (toppos < 0) toppos = 0 ;


  var url = "swfplayer.php?url=" + url + "&width="+awidth+"&height="+aheight+"&title="+escape(atitle)+"&urloption="+aflag+"";
  var elposwfplay = window.open(url,"elposwfplay","width="+winwidth+",height="+winheight+",left="+leftpos+",top="+toppos+"");
  if (!elposwfplay)
  {
	knuPopupBlocked();
  }
  else
  {
   elposwfplay.focus();
  }

}


function DoZusatzEintrag(pageid,catid,param,func)
{
  var url = "knodata.php?cmd=zse&pageid=" + pageid + "&catid="+catid+"&aparam="+escape(param)+"&func="+escape(func)+"";
  var elknowin = window.open(url,"elposwfplay","width=800,height=600,left=10,top=10,status=yes,resizable=yes");
  if (!elknowin)
  {
	knuPopupBlocked();
  }
  else
  {
   elknowin.focus();
  }

}

function DoZusatzEintragSnack(pageid,catid,param,func)
{
  var url = "knodata.php?cmd=zsesnack&pageid=" + pageid + "&catid="+catid+"&aparam="+escape(param)+"&func="+escape(func)+"";
  var elknowin2 = window.open(url,"elposwfplay","width=800,height=600,left=10,top=10,status=yes,resizable=yes");
  if (!elknowin2)
  {
	knuPopupBlocked();
  }
  else
  {
   elknowin2.focus();
  }

}

function DoKeywordHelper(pageid,param,func)
{
  var url = "knodata.php?cmd=kwh&pageid=" + pageid + "&aparam="+escape(param)+"&func="+escape(func)+"";
  var elknowin = window.open(url,"elposwfplay","width=800,height=600,left=10,top=10,status=yes,resizable=yes");
  if (!elknowin)
  {
	knuPopupBlocked();
  }
  else
  {
   elknowin.focus();
  }

}

function GetBandwidth()
{
  return defaultBandwidth;
}

function SetDefaultBandwidth(n)
{

  if (n >=1 && n <=3)
    defaultBandWidth = n;
}

function startPlayer(aClip)
{
  var aSkin = "easylearn" ;
  var wmpUrl = "" ;
  var isMac = navigator.userAgent.indexOf("Mac") >= 0 ;

  if (!isMac && (b_winmp7 == true) && document.all)
  {
     wmpUrl = unescape(aClip) + "?WMPSkin=" + aSkin;
     document.location = wmpUrl;
  }
  else
  {
     wmpUrl = unescape(aClip);
     document.location = wmpUrl;
  }
}


function closeTemporaryPlayerWin()
{
  try
  {
    if (temporaryplayerwin != null && !temporaryplayerwin.closed)
    {
    	temporaryplayerwin.close();
    }
  }
  catch(e)
  {

  }
}

function startPlayerNewDoc(aClip)
{
  var aSkin = "easylearn" ;
  var wmpUrl = "" ;
  var isMac = navigator.userAgent.indexOf("Mac") >= 0 ;
  var win;


  if (!isMac && (b_winmp7 == true) && document.all)
  {
     wmpUrl = unescape(aClip) + "?WMPSkin=" + aSkin;

  }
  else
  {
     wmpUrl = unescape(aClip);
  }
  temporaryplayerwin = window.open(wmpUrl,"","width=100,height=100");
  if (temporaryplayerwin)
  {
    //temporaryplayerwin.blur();
    window.setTimeout("closeTemporaryPlayerWin()", 10000);
  }
}


function closeAwin(awin)
{
  try
  {
    awin.close();
  }
  catch(e)
  {

  }
}

function getCookieVal (offset)
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen)
  {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value)
{
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name)
{
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
