// functions for cookies

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,expires,path,domain,secure) {
 document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
 if (GetCookie(name)) { document.cookie = name + "=" +	 ((path) ? "; path=" + path : "") +	 ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; }
}

// functions for window handling
var isopen=false;

function winClose(winname)
{ winname.close(); }

function winOpen(url,windowname,breite,hoehe,scroll,resize,tool,status,menu,location)
{ if( (isopen) && (!popUp.closed) ){ winClose(popUp); }
    popUp = window.open(url,windowname,"width="+breite+",height="+hoehe+",screenX=40,screenY=20,scrollbars="+scroll+",resizable="+resize+",toolbar="+tool+",status="+status+",menubar="+menu+",location="+location+""); 
  isopen=true;
}

function winOpenOnce(url,windowname,breite,hoehe,scroll,resize,tool,status,menu)
{ var popval = GetCookie(windowname);
  if (popval == null) {
     popval=1;
     SetCookie(windowname, popval, "", "/","mediamarkt.de");
     var test = GetCookie(windowname);
     if (test != null){winOpen(url,windowname,breite,hoehe,scroll,resize,tool,status,menu);}
  }
}

// functions for select boxes
function choice()
{ 
  var zielHistory = document.Lexikon.history.value;
  var zielWert = document.Lexikon.termID;
  var zielName = zielWert.options[zielWert.selectedIndex].value;
  var zielURL = "/lexikon/index.php";	
			
  if( zielName != '')
  { document.location.href = zielURL + "?termID=" + zielName + "&history=" + zielHistory;	}
  else	
  { document.Lexikon.reset(); }	
}

// functions for explain layer
function explain(e,TermName,explText,TermId)
{  // opens explanation layer with text "explText" near mouse position
   // e is the event causing call to explain(), please provide explain(event,...) here
   // TermName is the name of the term, eg. "DVD" or "Wireless LAN"
   // explText is the text explaining the term
   // TermId is the ID of the term with db Lexikon 
   var ns = navigator.appName == "Netscape";
   var ns4 = (ns && parseInt(navigator.appVersion) == 4);
   var ns5 = (ns && parseInt(navigator.appVersion) > 4);

    // get mouse position
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }

   // get layer layExplain object
   if (ns4) myLayer = document["layExplain"]; 
   else if (ns5) myLayer = document.getElementById("layExplain");
   else myLayer = document.all ? document.all["layExplain"] : null;

   // get  txtExplain paragraph
   if (ns4) txtPara = document["txtExplain"]; 
   else if (ns5) txtPara = document.getElementById("txtExplain");
   else txtPara = document.all ? document.all["txtExplain"] : null;

   // get lexLink linkage
   if (ns4) lexText = document["lexLink"];
   else if (ns5) lexText = document.getElementById("lexLink");
   else lexText = document.all ? document.all["lexLink"] : null;
   TermId = '/lexikon/?termID=' + TermId;

   // add IVW-Gif to text ca. jedes 2. Mal
   //zufallszahl = Math.round(Math.random() * 100);
   //	if(zufallszahl % 2 == 0)
   //	{
   TermName = escape(TermName);
   explText = '<BR>' + explText + '<BR><BR><IMG SRC="/cgi-bin/ivw/CP/lexikon/explain/' + TermName + '" WIDTH="1" HEIGHT="1">';
   //	}



   // write text and move into visible area
   if (myLayer) {
           txtPara.innerHTML = explText;
	   lexText.href = TermId;
	   myLayer.style.left=xMousePos - 20;
	   myLayer.style.top=yMousePos - 30;
   }
}

function unexplain()
{  // hides explanation layer

   var ns = navigator.appName == "Netscape";
   var ns4 = (ns && parseInt(navigator.appVersion) == 4);
   var ns5 = (ns && parseInt(navigator.appVersion) > 4);

   // get layer layExplain object
   if (ns4) myLayer = document["layExplain"]; 
   else if (ns5) myLayer = document.getElementById("layExplain");
   else myLayer = document.all ? document.all["layExplain"] : null;

   // get  txtExplain paragraph
   if (ns4) txtPara = document["txtExplain"]; 
   else if (ns5) txtPara = document.getElementById("txtExplain");
   else txtPara = document.all ? document.all["txtExplain"] : null;

   // move out of visible area
   if (myLayer) {
	   txtPara.innerHTML = "";
	   myLayer.style.left=0;
	   myLayer.style.top=-100;
   }
}

function parentloader (url)
{
	parent.opener.location.href=url;
	return;
}

