// JScript File
	var NOT_INSTALLED = 2;
    var WRONG_VERSION = 4;
    var INSTALLED = 1;
	var NOT_ENABLE = 3;
	var NOT_DETECTABLE = 5;
	var detect = navigator.userAgent.toLowerCase();
	var webstartAvailable;
	var windowsIE = (checkPlatform("msie") && checkPlatform("win"));
	//var isIE7 = windowsIE && window.XMLHttpRequest;
	var isIE7 = false;
	function checkPlatform(string)
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}
    function isJavaPluginInstalled(requiredVersion) 
    {
        if (navigator.userAgent.indexOf("MSIE") != -1) 
        {
            try 
            {
                var plugin = new ActiveXObject("JavaPlugin");
				
                if (plugin) {
                    var curr = -1;
                    for (var n1 = 1; n1 >= 1 && curr == -1; --n1) {
                        for (var n2 = 9; n2 >= 0 && curr == -1; --n2) {
                            for (var n3 = 9; n3 >= 0 && curr == -1; --n3) {
                                for (var n4 = 9; n4 >= 0 && curr == -1; --n4) {
                                    for (var n5 = 9; n5 >= 0 && curr == -1; --n5) {
                                        var version = "" + n1 + n2 + n3 + "_" + n4 + n5;
                                        try {
                                            var versioned = new ActiveXObject("JavaPlugin." + version);
                                            curr = new Number("" + n1 + n2 + n3);
											
                                        }
                                        catch (e) {
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (curr == null) curr = "120";
                    var array = requiredVersion.split(".");
                    var convert = new Number(array[0]) * 100;
                    if (array.length > 1) convert += new Number(array[1]) * 10;
                    if (array.length > 2) convert += new Number(array[2]);
                    if (curr >= convert)
					{
						if(!navigator.javaEnabled())
						{
							 return NOT_ENABLE;
						}
                        return INSTALLED;
					}
                    else
					{
                        return WRONG_VERSION;
					}
                }
             return NOT_INSTALLED; 
            }
            catch (e) 
            {
                if (e.message == "Automation server can't create object")
                    return NOT_INSTALLED;
                else {
                    alert(e.message);
                    throw e;
                }
            }
        }

	}
	if (navigator.mimeTypes && navigator.mimeTypes.length) 
	{
		webstartAvailable = navigator.mimeTypes['application/x-java-jnlp-file'];
	}

	function webstartVersionCheck(versionString)
	{ 
        try 
        {
			if(!navigator.plugins) {	navigator.plugins.refresh(true);	}
			var installed = false;
			if (navigator.mimeTypes['application/x-java-jnlp-file']) 
			{	
				/*
				var allPlugin = '';
				for (var i = 0; i < navigator.mimeTypes.length; ++i) 
				{
					allPlugin += navigator.mimeTypes[i].type + '\n';
				}
				alert(allPlugin);
				*/
				for (var i = 0; i < navigator.mimeTypes.length; ++i) 
				{
					pluginType = navigator.mimeTypes[i].type;
					//if(pluginType.indexOf("application/x-java-applet;version=")) // dude, this line will always return true
					if(pluginType.indexOf("application/x-java-applet;version=") >= 0)
					{
						installed = true;
					}
					if(pluginType.indexOf("application/x-java-applet;version=" + versionString) >= 0)
					{
						if(!navigator.javaEnabled())
							{
								return NOT_ENABLE;
							}

						return '1';
					}
				}
				if(installed)
				{ return WRONG_VERSION; }	 else	 {	 return NOT_INSTALLED;}
			}
			else
			{		 return NOT_INSTALLED;		 }
		}
        catch (e) 
        {
			return NOT_INSTALLED;
        }
	 }
 
function check1(jversion)
{
	if(navigator.platform.indexOf("Mac") >= 0) // java should be already installed in mac, and not able to check on browser
	{
		return INSTALLED;	
	}
	else
	{
		if (isIE7)
		{
			return NOT_DETECTABLE;
		}
  		else if (windowsIE) 
		{	
			return isJavaPluginInstalled(jversion); 
		}
		else
		{ 
			return webstartVersionCheck(jversion);
		}
	}
}
 
 
function chek()
{
	var res = check1("1.5");
	//var res = getCookie('chkjava');
	//alert('res=' + res);
	//if(res == null)
	//{
		//res = check1("1.5");
		
	if(res == null || res =="0")
	{
		if (document.getElementById("javatest"))
		{
			res = document.getElementById("javatest").innerHTML;
		}
		else
		{
			res = document.javatest.innerHTML;
		}
	}
		
	if(res =='1')
	{
		/*
		var confirmtext = "We have noticed that your computer does not have the Java Run Time Engine installed or the version that you currently have is outdated.\n\n";
		confirmtext += "You will be required to enable the Java Runtime Engine in order to download your digital music files after purchase.\n\n";
		confirmtext += "Do you wish to add these digital files to your cart?";
		setCookie('chkjava',res,'7');
		return confirm(confirmtext);
		*/
		return true;  
	}
	else  
	{
		//switch(res) // switch, case or break causing issue in IE7
		//{
			// "java is not installed"
			//case '2' :
			if (res == NOT_INSTALLED)
				{
					var confirmtext = "We have noticed that your computer does not have the Java Run Time Engine installed or the version that you currently have is outdated.\n\n";
					confirmtext += "You will be required to enable the Java Runtime Engine in order to download your digital music files after purchase.\n\n";
					confirmtext += "Do you wish to add these digital files to your cart?";
					setCookie('chkjava',res,'7');
					return confirm(confirmtext);
					//break;
				}
			// "java is not enabled from browser"
			//case '3' :
			if (res == NOT_ENABLE)
				{
					var confirmtext = "We have noticed that your computer does not have the Java Run Time Engine enabled.\n\n";
					confirmtext += "You will be required to enable the Java Runtime Engine in order to download your digital music files after purchase.\n\n";
					confirmtext += "Do you wish to add these digital files to your cart?";
					setCookie('chkjava',res,'7');
					return confirm(confirmtext);
					//break;
				}
			// "java version upgrade , required"
			//case '4' :
			if (res == WRONG_VERSION)
				{
					var confirmtext = "We have noticed that your computer does not have the Java Run Time Engine installed or the version that you currently have is outdated.\n\n ";
					confirmtext += "You will be required to enable the Java Runtime Engine in order to download your digital music files after purchase.\n\n";
					confirmtext += "Do you wish to add these digital files to your cart?";
					setCookie('chkjava',res,'7');
					return confirm(confirmtext);
					//break;
				}	
			if (res == NOT_DETECTABLE)
				{	
					var isDisplayed = getCookie('isIE7');
					if (isDisplayed == null)
					{
						var confirmtext = "Java version 1.5 or higher is required to download Digital Music Files.\n";
						confirmtext += "Java is a free program and easy to install. Our FAQ will assist with this simple process if necessary after the purchase process.\n\n";
						confirmtext += "Do you wish to add these digital files to your cart?";
						//setCookie('isIE7',1,7);
						return confirm(confirmtext);
					}
				}	
		//} 
		return false;	  
	} 
	//}
	//else alert(res);
}

function showhide(id)
{ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		} 
	} 
}

function show(id)
{ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj != null){ 
			obj.style.display = ""; 
		} 
	} 
} 

function hide(id)
{ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj != null){ 
			obj.style.display = "none"; 
		} 
	} 
}  
  
function confirmchek()
{
	var res = check1("1.5");
	
	if(res == null || res =="0")
	{
		if (document.getElementById("javatest"))
		{
			res = document.getElementById("javatest").innerHTML;
		}
		else
		{
			res = document.javatest.innerHTML;
		}
	}

	setCookie('chkjava',res,'7');
	if(res =='1')
	{
		show('dvDownloadInstructions');
		hide('dvDownloadInstructionsNoJava');
		hide('dvDownloadInstructionsDisabled');
		hide('dvDownloadInstructionsNotDetectable');
	}
	else  
	{
		//alert(res);
		//switch(res)
		//{
			// "java is not installed"
				//case '2' :
			if (res == NOT_INSTALLED)
				{
					hide('dvDownloadInstructions');
					show('dvDownloadInstructionsNoJava');
					hide('dvDownloadInstructionsDisabled');
					hide('dvDownloadInstructionsNotDetectable');
					//break;
				}
			// "java is not enabled from browser"
			//case '3' :
			if (res == NOT_ENABLE)
				{
					hide('dvDownloadInstructions');
					hide('dvDownloadInstructionsNoJava');
					show('dvDownloadInstructionsDisabled');
					hide('dvDownloadInstructionsNotDetectable');
					//break;
				}
			// "java version upgrade , required"
			//case '4' :
			if (res == WRONG_VERSION)
				{
					hide('dvDownloadInstructions');
					show('dvDownloadInstructionsNoJava');
					hide('dvDownloadInstructionsDisabled');
					hide('dvDownloadInstructionsNotDetectable');
					//break;
				}	
			if (res == NOT_DETECTABLE) // IE7, Mac, etc
				{	
					hide('dvDownloadInstructions');
					hide('dvDownloadInstructionsNoJava');
					hide('dvDownloadInstructionsDisabled');
					show('dvDownloadInstructionsNotDetectable');
				}			
		//} 
		return false;	  
	} 
}


function setCookie(NameOfCookie, value, expiredays)
{

	// Three variables are used to set the new cookie.
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning
	// the values to the "document.cookie" object.
	// Note the date is converted to Greenwich Mean time using
	// the "toGMTstring()" function.

	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}


function getCookie(NameOfCookie)
{
	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.

	if (document.cookie.length > 0)
	{
		// Second we check to see if the cookie's name is stored in the
		// "document.cookie" object for the page.

		// Since more than one cookie can be set on a
		// single page it is possible that our cookie
		// is not present, even though the "document.cookie" object
		// is not just an empty text.
		// If our cookie name is not present the value -1 is stored
		// in the variable called "begin".

		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) // Note: != means "is not equal to"
		{
			// Our cookie was set.
			// The value stored in the cookie is returned from the function.

			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;

	// Our cookie was not set.
	// The value "null" is returned from the function.

}