function stripName(i_Path) {
	var thePath = new String(i_Path);
	var Pos = 0;
	while (Pos != -1) {
		Pos = thePath.indexOf("/");
		if (Pos != -1) {
			thePath = thePath.substring(Pos+1,thePath.length);
		}
	}
	do {
		Pos = thePath.lastIndexOf(".");
		if (Pos != -1) {
			thePath = thePath.substring(0,Pos);
		}
	} while (Pos != -1);
	return thePath;
}

function select(theItem) {
	var theFrame;
	var ItemName = stripName(theItem);
	//window.alert("parent.frames " + parent.frames["CONTENT"].location.href);
	for (var i=0;i<document.images.length;i++) {
			var but=document.images[i];
			//alert("Comparing " + but.name + " and " + theItem);
			if (but.name == ItemName) {
					but.src="../images/" + ItemName + "_g.png";
			} else {
					but.src="../images/" + but.name + ".png";
					//window.alert(but.name + " nicht gedrückt! ");
			}
	}
	if (theFrame=document.getElementById("theContent")) {
		//status = "WC3 DOM detected";
	}
	else if (document.activeElement != null) {
		//status = "IE4 DOM detected";
		//theFrame=document.all["theContent"];
		theFrame=parent.CONTENT;
	}
	else {
		theFrame=parent.CONTENT;
		//status = "Legacy DOM detected";
	}
	//alert(theFrame);
	theFrame.location.href=theItem;
	//alert(theItem + "," + ItemName);
}


function show_props(obj, obj_name) {
   var result = "";
   for (var i in obj)
      result += obj_name + "." + i + " = " + obj[i] + "\n";
   return result;
}

function getCookie(name){
	// split cookies into array
	var cookies = document.cookie.split("; ");
	//alert(cookies);
	for (var i=0;i<cookies.length;i++) {
	var c=cookies[i];
	var pos=c.indexOf('=');
	var n=c.substring(0,pos);
	if (n==name)
		return c.substring(pos+1);
	}
	return null;
}

function setMyCookie(to) {
	var ExpDate=new Date();
	var NewDay = ExpDate.getDate()+7;
	if (NewDay>=28) {	// worst case we expire 3 days later
		NewDay -= 28;
		var Month = ExpDate.getMonth()+1;
		if (Month>11) {
			Month=0;
			ExpDate.setFullYear(ExpDate.getFullYear()+1);
		}
		ExpDate.setMonth(Month);
	}
	ExpDate.setDate(NewDay);
	var Cookie = "LicenseAccepted=" + to + ";";
	Cookie += "expires=";
	Cookie += ExpDate.toGMTString();
	//alert("set cookie: " + Cookie);
	document.cookie = Cookie;
}

function show_plugins() {
	var res = "<p>Plugin Info</p>"
	for (var j=0;j<navigator.plugins.length;j++) {
		var p=navigator.plugins[j];
		res += "<p>" + j + " " + p.name;
		res += show_props(p,"plugin[" + j + "]");
		res += "</p>";
		//if (j == 5) break;
	}
	return res;
}

function _showLicenseAndDownload(FileURL,bAlternateLocation,language) {
	var theHRef;
	/*
	var Complete=new String(document.location.href);
	var Start = Complete.indexOf(document.location.pathname);
	var Base=Complete.slice(0,Start);
	status="Loading " + Base + "/" + FileURL;
	*/
	//open(FileURL,"","");
	//parent.CONTENT.location.href=FileURL;
	if (getCookie("LicenseAccepted")=="yes") {
		// download immediately
		if (bAlternateLocation) {
			//theHRef="http://www.nefkom.net/Heckmann/clips/" +  FileURL + ".mp3";
			theHRef = "../php/download.php?clip=" + encodeURIComponent(FileURL) + "&alt=1&lang=" + language;
		} else {
			//theHRef="../clips/" +  FileURL + ".mp3";
			theHRef = "../php/download.php?clip=" + encodeURIComponent(FileURL) + "&alt=0&lang=" + language;
		}
	} else {
		if (bAlternateLocation) {
			theHRef="Nutzung" + ".html?a=1&lang=" + language + "d=" + FileURL;
		} else {
			theHRef="Nutzung" + ".html?a=0&lang=" + language + "d=" + FileURL;
		}
	}
	//WindowToClose=open(theHRef,"","width=640,height=480,scrollbars=yes,status=yes,dependent=yes");
	location.href = theHRef;
	//WindowToClose.document.DownloadURL=new String(FileURL);
}

/*
function showLicenseAndDownload(c,a){
_showLicenseAndDownload(c,a,"de");
}
*/

function setCookieAndContinue() {
	var Download;
	var Alt,Clip,lang;
	//set cookie (always)
	setMyCookie("yes");
	//and continue, but only if we come from the download button
	if (location.search) {
		Alt = location.search.slice(3,4);
		lang = location.search.slice(10,12);
		Clip = location.search.slice(14);
		if (Alt == "1") {
			Download= "http://www.nefkom.net/Heckmann/clips/" + Clip;	// cut off "?a=xd="
		} else {
			Download= "../clips/" + Clip;	// cut off "?a=xd="
		}
		Download += ".mp3";
		//alert("setCookieAndContinue: " + Download);
		//location.href=Download;
		location.href = "../php/download.php?clip=" + Clip + "&alt=" + Alt + "&lang=" + lang;
		//close();
	}
}

function clearCookie() {
	setMyCookie("no");
	close();
}

function selectStart() {
	// selects the start page depending on the language

	var theLanguage;
	if (navigator.language == null) {
		theLanguage = navigator.userLanguage;
	} else {
		theLanguage = navigator.language;
	}
	//alert(theLanguage );
	if (theLanguage.match("de.*")) {
		location.href = "./deutsch/frameset.html";
	} else if (theLanguage.match("en.*")) {
		location.href = "./english/frameset.html";
	}
}
