// Copyright by OnClassical - Kunst der Fuge, © 2005-07

function addbookmark() {
	if (window.external) {
		external.AddFavorite('http://www.kunstderfuge.com/', 'Kunst der Fuge: 15.000+ free Classical MIDI files, (c) 2002-06')
		}
	else {
		alert("Your browser doesn't support this feature.\n" +
	"If you are using Netscape or Mozilla Firefox\n" +
	"then go to 'Bookmarks' or simply press Ctrl+D.");
	}
	}

function MM_displayStatusMsg(msgStr) 
	{ 
		status=msgStr;
		document.MM_returnValue = true;
	}

// Test on cookies to activate the site!

function cookiesTest(){
	setCookie('test','yes',365);
	if(getCookie('test')!='yes'){
		window.location='http://www.kunstderfuge.com/-/cookies.asp'
	}
	delCookie('test');
}

function getCookie(NameOfCookie)
	{
	if (document.cookie.length > 0) 
		{              
		begin = document.cookie.indexOf(NameOfCookie+"=");       
		if (begin != -1)
			{           
			begin += NameOfCookie.length+1;       
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
			} 
		}
		return null;
	}

	function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString())+ "; path=/";
	}

	function delCookie (NameOfCookie) {
		if (getCookie(NameOfCookie)) {
			document.cookie = NameOfCookie + "=" +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT ; path=/" ;
		}
	}

function midi(url) 
{
		var pageasp="http://www.kunstderfuge.com/-/engine.asp?file=";
		var newurl = pageasp+url;
             
		TextContent=getCookie('test');
	
		// alert('I check the cookies status, that it is:'+ TextContent);
		// If there is yes cookie was previously activated
		// If there is null cookie doesn't exist
		// If the cooki was previously created, I'm now going to verify if I can change it
		if(TextContent=='yes')
			{
			delCookie('test')						// I delete the cookie and then try to see if I have cancelled it
			StatusCookie=getCookie('test');					// if StatusCookie = null means that cookie can be cancelled, then cookies are active 
			if(StatusCookie==null )
				{
				// setCookie('test','yes',365);	
				// TestCookieAttivi=getCookie('test');
				// alert('1:TestAttivi:'+TestCookieAttivi);
				// if (TestCookieAttivi!=null)
				// {
			// alert('url1:'+newurl); 
			window.location.href=newurl;
			}
			else 
				{
				alert('Please enable your cookies before to download!');
				// window.location.href=newurl;
				}
			}

			// }		
	 
			else 
			{
				// alert('Caso 2: il cookie vale Null='+TextContent );  // It's null because it was not found as active	
				setCookie('test','yes',365);				// I try to write a cookie 
				statusCookie=getCookie('test');				// I'm trying seeing if I can write it 
				// alert('Caso 2: il cookie vale:-->'+statusCookie );  

				if (statusCookie=='yes')
				{
				// setCookie('test','yes',365);	
				// TestCookieAttivi=getCookie('test');
				// alert('2:TestAttivi:'+ TestCookieAttivi);
				// if (TestCookieAttivi!=null)
				// {
				// alert('url2:'+newurl);  
			window.location.href=newurl;
			}
			else 
			{
			alert('Please enable your cookies before to download!');
			// window.location.href=newurl;
			}
		}
	// }
	}
	
	function Do(NameOfCookie) 
		{
		delCookie(NameOfCookie)
		setCookie(NameOfCookie,'yes',365);
		}