function tDrucken()
		{
		PrintWnd = window.open('',"Drucken",'top=20,left=50,width=400, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
		PrintWnd.document.open("text/html");		
		PrintWnd.document.write("<html><head><title>Text</title></head><body>");
		PrintWnd.document.write("<h1>Text</h1>");
		PrintWnd.document.write("<p><a href=javascript:window.print()>[Print Page]</a> <a href=javascript:window.close()>[Close Page]</a></p>");
		PrintWnd.document.write("<table border=\"1\" width=\"364\">");
		PrintWnd.document.write("<tr>");
		PrintWnd.document.write("<td>");
		PrintWnd.document.write(document.ssk.holeText());
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr></table>");
		PrintWnd.document.write("<p><font size=\"1\">© <a href=\"http://www.vision-7.com\">www.vision-7.com</a></font></p>");
		PrintWnd.document.write("</body></html>");
		PrintWnd.document.close();
		}

function printStrokes() {
		PrintWnd = window.open('',"Drucken",'top=20,left=50,width=400, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
		PrintWnd.document.open("text/html");		
		PrintWnd.document.write("<html><head><title>Anschläge</title></head><body>");
		PrintWnd.document.write("<h1>Anschläge</h1>");
		PrintWnd.document.write("<p><a href=javascript:window.print()>[Print Page]</a> <a href=javascript:window.close()>[Close Page]</a></p>");
		PrintWnd.document.write("<table border=\"1\" width=\"364\">");
		PrintWnd.document.write("<tr>");
		PrintWnd.document.write("<td>");
		PrintWnd.document.write(document.ssk.getEnteredText());
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr></table>");
		PrintWnd.document.write("<p><font size=\"1\">© <a href=\"http://www.vision-7.com\">www.vision-7.com</a></font></p>");
		PrintWnd.document.write("</body></html>");
		PrintWnd.document.close();
}

function printApplet(Lektion,Sprache,Tastatur) {

	var TicRate = GetCookie("TicRate");
	if (!TicRate) TicRate = 0;
	var TicRateIndex = GetCookie("TicRateIndex");
	if (!TicRateIndex) TicRateIndex = 0;
	var AccousticControl = GetCookie("AccousticControl");
	if (!AccousticControl) AccousticControl = true;
	var OpticControl = GetCookie("OpticControl");
	if (!OpticControl) OpticControl = true;

	document.write('<applet name="ssk" CODE="ssk.class"  codebase="../../java/" WIDTH="598" HEIGHT="348" MAYSCRIPT>');
	document.write('<param name="AccousticControl" value="'+AccousticControl+'">');
	document.write('<param name="Lektion" value="'+Lektion+'">');
	document.write('<param name="OpticControl" value="'+OpticControl+'">');
	document.write('<param name="Sprache" value="'+Sprache+'">');
	document.write('<param name="Tastatur" value="'+Tastatur+'">');
	document.write('<param name="TicRate" value="'+TicRate+'">');
	document.write('<param name="TicRateIndex" value="'+TicRateIndex+'">');
	document.write('<br>Ihr Browser unterstützt kein Java!Sie können folgendes tun:<br><br>Wenn Sie Windows verwenden, klicken Sie auf diesen <a href=http://www.java.com/de/download/windows_automatic.jsp><font color="#000000">Link</a>,<font color="#00679C"> um die Java Virtual Machine von Sun zu installieren. Dazu brauchen Sie eine Internetverbindung.<br>Eine detailierte Installationsanleitung finden Sie <a href=http://www.vision-7.com/support/ssk35_d.php><font color="#000000">hier<font color="#00679C"></a>.<br><br>Verwenden Sie ein anderes Betriebsystem, lesen Sie bitte die <a href=http://www.vision-7.com/support/ssk35_d.php><font color="#000000">Hilfe<font color="#00679C"></a>.');	document.write('</applet>');
}

function save() {
//	alert(1);return;
// today
var now = new Date();

// one year in milliseconds
var one_year = 365*24*60*60*1000;

// one hour in milliseconds
var one_hour = 1*60*60*1000;

// expires in one year from now on
var expire_date = new Date();
expire_date.setTime(now.getTime()+one_year);

/*
alert(navigator.appCodeName); // Mozilla
alert(navigator.appName); // Microsoft Internet Explorer
alert(navigator.appVersion); // 4.0 (compatible; MSIE 4.01; Macintosh; I;PPC)
alert(navigator.platform); // MacPPC
alert(navigator.userAgent);// Mozilla/4.0...
*/
SetCookie ("TicRate", document.ssk.getTicRate(), expire_date, "/");
SetCookie ("TicRateIndex", document.ssk.getSelectedTicRate(), expire_date, "/");
SetCookie ("AccousticControl", document.ssk.getAccousticControl(), expire_date, "/");
SetCookie ("OpticControl", document.ssk.getOpticControl(), expire_date, "/");

}
/*
function isMacIE() {
	var browser = navigator.appVersion;
	var ie = browser.search(/msie/i);
	var mac = browser.search(/mac/i);
	if(ie==-1 || mac==-1) {
		return false;
	}
	return true;
}
*/

function fDrucken()
		{
		Name = prompt("Enter Name","");
		Kommmentar = prompt("Enter Comments","");
		PrintWnd = window.open('',"Print",'top=20,left=50,width=400, toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
		PrintWnd.document.open("text/html");		
		PrintWnd.document.write("<html><head><title>Statistics</title></head><body>");
		PrintWnd.document.write("<h1>Statistics</h1>");
		PrintWnd.document.write("<p><a href=javascript:window.print()>[Print Page]</a> <a href=javascript:window.close()>[Close Page]</a></p>");
		PrintWnd.document.write("<table border=\"1\" width=\"364\">");
		PrintWnd.document.write("<tr>");
		PrintWnd.document.write("<td width=\157\">Name:</td>");
		PrintWnd.document.write("<td width=\"191\">");
		PrintWnd.document.write(Name);
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"157\">Comments:</td>");
		PrintWnd.document.write("<td width=\"191\">");
		PrintWnd.document.write(Kommmentar);
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"157\">Computer:</td>");
		PrintWnd.document.write("<td width=\"191\">");
		PrintWnd.document.write(document.ssk.holeIP());
		PrintWnd.document.write("&nbsp;");
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr></table>");
		PrintWnd.document.write("<p>");
		PrintWnd.document.write(document.ssk.UpdateFinger());
		PrintWnd.document.write("</p>");
		PrintWnd.document.write("<table border=\"1\" width=\"364\">");
		PrintWnd.document.write("<tr><td width=\"158\">Excercise:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.getParameter("Lektion"));
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">End Excercise:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeLektionBeendet());
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"157\">Total errors:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeTotalFehler());
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Error rate:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeFehlerrate());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Keystrokes per minute:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeAnschlaegeProMinute());
		PrintWnd.document.write("</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Little Finger Left:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeKleinfingerLinks());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Ring-Finger Left:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeRingfingerLinks());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Middle-Finger Left:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeMittelfingerLinks());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Index-Finger Left:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeZeigfingerLinks());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Thumb:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeDaumen());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Little Finger Right:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeKleinfingerRechts());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Ring-Finger Right:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeRingfingerRechts());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Middle-Finger Right:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeMittelfingerRechts());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr><tr>");
		PrintWnd.document.write("<td width=\"158\">Index-Finger Right:</td>");
		PrintWnd.document.write("<td width=\"190\">");
		PrintWnd.document.write(document.ssk.holeZeigfingerRechts());
		PrintWnd.document.write("&nbsp;%</td>");
		PrintWnd.document.write("</tr></table>");
		PrintWnd.document.write("<p><font size=\"1\">© <a href=\"http://www.vision-7.com\">www.vision-7.com</a></font></p>");
		PrintWnd.document.write("</body></html>");
		PrintWnd.document.close();
		PrintWnd.document.focus();
}


var bookmarkurl;
var bookmarktitle;

function displayFavorites(szTitle, ieText, otherText)
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
	   	if (navigator.platform.indexOf("Mac") != -1) 
	   	{
	   	} else
	   	{

			bookmarkurl=document.location;
			bookmarktitle=szTitle;

			document.write('<style type="text/css">');
			document.write('#element1 {position: absolute; top: 58px; left: 600px; }');
			document.write('#element2 {position: absolute; top: 58px; left: 620px; }');
			document.write('#element3 {position: absolute; top: 58px; left: 640px; }');
			document.write('</style>');

			if (document.images.spacer)
			{
//				document.write('<div ID="element1">');
//				document.write('<a href="javascript:fDrucken();"><img border="0" src="../statistik.gif" alt="Statistik drucken" width="16" height="18"></a>');
//				document.write('</div>');

				document.write('<td width="28" height="33"><a href="javascript:tDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image47','','../images/icon1_d.gif',1) ")

				document.write('"><img name="Image47" border="0" src="../images/icon1_hell.gif" width="25" height="33" alt="Text drucken"></a></td>')


				document.write('<td width="28" height="33"><a href="javascript:printStrokes();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image40','','../images/icon2_d.gif',1) ")

				document.write('"><img name="Image40" border="0" src="../images/icon2_hell.gif" width="25" height="33" alt="Anschläge drucken"></a></td>')


				document.write('<td width="28" height="33"><a href="javascript:fDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image48','','../images/icon4_d.gif',1) ")

				document.write('"><img name="Image48" border="0" src="../images/icon4_hell.gif" width="25" height="33" alt="Statistik drucken"></a></td>')

			}


				document.write('<td width="28" height="33"><a href="javascript:window.external.AddFavorite(bookmarkurl,bookmarktitle);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(')

				document.write("'Image41','','../images/icon3_d.gif',1)")
				document.write('"><img name="Image41" border="0" src="../images/icon3_hell.gif" alt="Zu Favoriten hinzufügen" width="25" height="33"></a></td>')
		

 

	

	        }
	
	}
	else 
	{
		if (navigator.platform.indexOf("Mac") != -1) 
		{
			document.write('<style type="text/css">');
			document.write('#element1 {position: absolute; top: 52px; left: 600px; }');
			document.write('#element2 {position: absolute; top: 52px; left: 620px; }');
			document.write('#element3 {position: absolute; top: 52px; left: 640px; }');
			document.write('</style>');

			if (document.images.spacer)
			{
//				document.write('<div ID="element1">');
//				document.write('<a href="javascript:fDrucken();"><img border="0" src="../statistik.gif" alt="Statistik drucken" width="16" height="18"></a>');
//				document.write('</div>');

				document.write('<td width="28" height="33"><a href="javascript:tDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image47','','../images/icon1_d.gif',1) ")

				document.write('"><img name="Image47" border="0" src="../images/icon1_hell.gif" width="25" height="33" alt="Text drucken"></a></td>')
				

				document.write('<td width="28" height="33"><a href="javascript:printStrokes();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image40','','../images/icon2_d.gif',1) ")

				document.write('"><img name="Image40" border="0" src="../images/icon2_hell.gif" width="25" height="33" alt="Anschläge drucken"></a></td>')


				document.write('<td width="28" height="33"><a href="javascript:fDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image48','','../images/icon4_d.gif',1) ")

				document.write('"><img name="Image48" border="0" src="../images/icon4_hell.gif" width="25" height="33" alt="Statistik drucken"></a></td>')

			}

			document.write('<td width="28" height="33"><a href="javascript:alert(');
			document.write("'Add Bookmark Apple-D');")
			document.write('" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(')
			document.write("'Image41','','../images/icon3_d.gif',1)")
			document.write('"><img name="Image41" border="0" src="../images/icon3_hell.gif" alt="Add Bookmark Apple-D" width="25" height="33"></a></td>')
               


		}
		else
		{
			document.write('<style type="text/css">');
			document.write('#element1 {position: absolute; top: 52px; left: 600px; }');
			document.write('#element2 {position: absolute; top: 52px; left: 620px; }');
			document.write('#element3 {position: absolute; top: 52px; left: 640px; }');
			document.write('</style>');

			if (document.images.spacer)
			{			
//				document.write('<div ID="element1">');
//				document.write('<a href="javascript:fDrucken();"><img border="0" src="../statistik.gif" alt="Statistik drucken" width="16" height="18"></a>');
//				document.write('</div>');

				document.write('<td width="28" height="33"><a href="javascript:tDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image47','','../images/icon1_d.gif',1) ")

				document.write('"><img name="Image47" border="0" src="../images/icon1_hell.gif" width="25" height="33" alt="Text drucken"></a></td>')


				document.write('<td width="28" height="33"><a href="javascript:printStrokes();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image40','','../images/icon2_d.gif',1) ")

				document.write('"><img name="Image40" border="0" src="../images/icon2_hell.gif" width="25" height="33" alt="Anschläge drucken"></a></td>')


				document.write('<td width="28" height="33"><a href="javascript:fDrucken();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(');
				document.write("'Image48','','../images/icon4_d.gif',1) ")

				document.write('"><img name="Image48" border="0" src="../images/icon4_hell.gif" width="25" height="33" alt="Statistik drucken"></a></td>')
			}

			document.write('<td width="28" height="33"><a href="javascript:alert(');
			document.write("'Add Bookmark CTRL-D');")
			document.write('" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(')
			document.write("'Image41','','../images/icon3_d.gif',1)")
			document.write('"><img name="Image41" border="0" src="../images/icon3_hell.gif" alt="Add Bookmark CTRL-D" width="25" height="33"></a></td>')

		}
	}
		
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

function displayMenu(arrMenu,name) {
	var urlString = String(document.location);
	var actualUnit = urlString.substring(0,urlString.lastIndexOf('/'));
	actualUnit = actualUnit.substring(actualUnit.lastIndexOf('/')+2);

	for(i=1;i<=arrMenu.length;i++) {
		document.write("<tr><td width=\"113\">");
		document.write('<!--mstheme--><font face="Arial">');
		link = arrMenu[i-1];
		document.write('<a href="../u'+i+'/'+link+'" ');
		j = i;
		if(i<10) j = '0'+i;
		if(actualUnit==i) {
			imgsrsc = "../images/"+name+"_"+j+"_o.gif";
		} else {
			document.write("onClick=\"MM_nbGroup('down','group1','"+name+i+"','../images/"+name+"_"+j+"_o.gif',1)\" ");
			document.write("onMouseOver=\"MM_nbGroup('over','"+name+i+"','../images/"+name+"_"+j+"_o.gif','',1)\" ");
			document.write("onMouseOut=\"MM_nbGroup('out')\"");
			imgsrsc = "../images/"+name+"_"+j+"_w.gif";
		}
		document.write(">");
		height = 17;
		if(i==1) height = 33;
		if(i==23) height = 20;
		document.write('<img name="'+name+i+'" src="'+imgsrsc+'" border="0" onLoad="" width="113" height="'+height+'">');
		document.write('</a>');
		document.write("</td></tr>");
	}
}

// ********************************************************************************
// cookie.js
// ********************************************************************************
//
//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.
//
//  This version takes a more aggressive approach to deleting
//  cookies.  Previous versions set the expiration date to one
//  millisecond prior to the current time; however, this method
//  did not work in Netscape 2.02 (though it does in earlier and
//  later versions), resulting in "zombie" cookies that would not
//  die.  DeleteCookie now sets the expiration date to the earliest
//  usable date (one second into 1970), and sets the cookie's value
//  to null for good measure.
//
//  Also, this version adds optional path and domain parameters to
//  the DeleteCookie function.  If you specify a path and/or domain
//  when creating (setting) a cookie**, you must specify the same
//  path/domain when deleting it, or deletion will not occur.
//
//  The FixCookieDate function must now be called explicitly to
//  correct for the 2.x Mac date bug.  This function should be
//  called *once* after a Date object is created and before it
//  is passed (as an expiration date) to SetCookie.  Because the
//  Mac date bug affects all dates, not just those passed to
//  SetCookie, you might want to make it a habit to call
//  FixCookieDate any time you create a new Date object:
//
//    var theDate = new Date();
//    FixCookieDate (theDate);
//
//  Calling FixCookieDate has no effect on platforms other than
//  the Mac, so there is no need to determine the user's platform
//  prior to calling it.
//
//  This version also incorporates several minor coding improvements.
//
//  **Note that it is possible to set multiple cookies with the same
//  name but different (nested) paths.  For example:
//
//    SetCookie ("color","red",null,"/outer");
//    SetCookie ("color","blue",null,"/outer/inner");
//
//  However, GetCookie cannot distinguish between these and will return
//  the first cookie that matches a given name.  It is therefore
//  recommended that you *not* use the same name for cookies with
//  different paths.  (Bear in mind that there is *always* a path
//  associated with a cookie; if you don't explicitly specify one,
//  the path of the setting document is used.)
//  
//  Revision History:
//
//    "Toss Your Cookies" Version (22-Mar-96)
//      - Added FixCookieDate() function to correct for Mac date bug
//
//    "Second Helping" Version (21-Jan-96)
//      - Added path, domain and secure parameters to SetCookie
//      - Replaced home-rolled encode/decode functions with Netscape's
//        new (then) escape and unescape functions
//
//    "Free Cookies" Version (December 95)
//
//
//  For information on the significance of cookie parameters, and
//  and on cookies in general, please refer to the official cookie
//  spec, at:
//
//      http://www.netscape.com/newsref/std/cookie_spec.html    
//
//******************************************************************
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
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 to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
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 to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
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";
  }
}

