// 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 zielTerm = document.Lexikon.term.value;
  var zielName = zielWert.options[zielWert.selectedIndex].value;
  var zielURL = "/lexikon/index.php";	
			
  if( zielName != '')
  { document.location.href = zielURL + "?termID=" + zielName + "&history=" + zielHistory + "&term=" + zielTerm;	}
  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;
        yMousePos = window.event.y;
    } 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;
}
// special
function isFull()
{
    // return true if something is selected!
	// if empty: openwin/return false
	if ( (document.Daten.vorname.value=="") || (document.Daten.nachname.value=="") || (document.Daten.strasse.value=="") || (document.Daten.plz.value=="") || (document.Daten.ort.value=="") || (document.Daten.email.value=="") || (document.Daten.geburtsdatum.value=="") )
	{
	    alert("Leider sind Ihre Angaben noch unvollständig. Bitte füllen Sie alle mit einem Sternchen gekennzeichneten Felder aus und senden Sie dann Ihre Anmeldung erneut ab. Vielen Dank.");
	     return;
	}

        if(document.Daten.teilnahmebedingungen.checked != true)
	{
	     alert("Sorry. Aber zur Absendung Ihrer Anmeldung ist es notwendig, dass Sie mit den Teilnahmebedingungen einverstanden sind. Bitte kreuzen Sie das Kästchen an und klicken Sie dann auf 'Abschicken'. Vielen Dank.");
		 return;
	}

        if (document.Daten.email.value != "")
	{
		emailaddr = document.Daten.email.value;
		ergebnis = emailaddr.search(/^[^@]+[@][^@]+.[^@]*$/);
		if (ergebnis == -1)
		{
			alert("Ihre E-Mail Adresse ist ungültig.");
			return;
		}
	}	
	PopUp();
	return;
}

function PopUp()
{
	document.Daten.submit();	
	alert("Ihre Daten wurden versandt. Danke für Ihre Teilnahme.");
 }

function PopUppinnacle(url, breite, hoehe) 
   {
      links = (screen.width/2)-(breite/2);
      oben = (screen.height/2)-(hoehe/2);
      window.open(url,'popup','height='+hoehe+',width='+breite+',toolbar=no,resizable=no,scrollbars=no,top='+oben+',left='+links);
   }



// Layer Ein-/Ausblenden
function ShowLayer(wert) 
  {
       if (document.layers) 
       {
            obj = eval("document."+wert);
       } 
       else 
       {
            obj = document.getElementById(wert);
	    obj = obj.style;
       } 
       obj.visibility = "visible";
 }
  function UnshowLayer(wert) 
  {
       if (document.layers) 
       {
            obj = eval("document."+wert);
       } 
       else 
       {
            obj = document.getElementById(wert);
            obj = obj.style;
       } 
       obj.visibility = "hidden";
  }


function SubmitCity()
{
     document.forms['MMCity'].elements['csi'].value=document.forms['MMCity'].elements['MMCityname'].selectedIndex;
     document.MMCity.submit();
}

function SubmitCity2()
{
     document.forms['MMCity2'].elements['csi'].value=document.forms['MMCity2'].elements['MMCityname'].selectedIndex;
     document.MMCity2.submit();
}

function SubmitCity3()
{
     document.forms['MMCity3'].elements['csi'].value=document.forms['MMCity3'].elements['MMCityname'].selectedIndex;
     document.MMCity3.submit();
}


