﻿var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

//fungsi untuk file flash yang ardin
var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );


// fungsi untuk jalanin jsnya Batmoaudio
function BatmoAudioPop(filedesc,artis,judul,filepath2,WindowNumber) 
{

var filepath=decode64(filepath2);

// Get Operating System 
var isWin = navigator.userAgent.toLowerCase().indexOf("windows") != -1
if (isWin) {
    // Use MIME type = "application/x-mplayer2";
	visitorOS="Windows";
} else {
    // Use MIME type = "audio/mpeg"; // or audio/x-wav or audio/x-ms-wma, etc.
	visitorOS="Other";
}

// Get the MIME type of the audio file from its extension (for non-Windows browsers)
var mimeType = "audio/mpeg"; // assume MP3/M3U
var objTypeTag = "application/x-mplayer2"; // The Windows MIME type to load the WMP plug-in in Firefox, etc.

var theExtension = filepath.substr(filepath.lastIndexOf('.')+1, 3); // truncates .aiff to aif
if (theExtension.toLowerCase() == "wav") { mimeType = "audio/x-wav"};
if (theExtension.toLowerCase() == "aif") { mimeType = "audio/x-aiff"}; 
if (theExtension.toLowerCase() == "wma") { mimeType = "audio/x-ms-wma"};
if (theExtension.toLowerCase() == "mid") { mimeType = "audio/mid"};
// Add additional MIME types as desired

if (visitorOS != "Windows") { 
objTypeTag = mimeType; // audio/mpeg, audio/x-wav, audio/x-ms-wma, etc.
};

/*{
	setTimeout (10000);
}*/

//bikin windownya
    PlayerWin = window.open('',WindowNumber,'width=320,height=217,top=0,left=0,screenX=0,screenY=0,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0');
	
    PlayerWin.focus();
    PlayerWin.document.writeln("<html><head><title>" + filedesc + "</title>");
	//PlayerWin.document.writeln("<script>");
	//PlayerWin.document.writeln("var howLong = 10000;");
	//PlayerWin.document.writeln("t = null;");
	//PlayerWin.document.writeln("function closeMe(){");
	//PlayerWin.document.writeln("t = setTimeout('self.close()',howLong);");
	//PlayerWin.document.writeln("}");
	//PlayerWin.document.writeln("</script>");
	PlayerWin.document.writeln("<script language='javascript'>");
	PlayerWin.document.writeln("document.oncontextmenu = function(){return false}");
	PlayerWin.document.writeln("if(document.layers) {");
	PlayerWin.document.writeln("window.captureEvents(Event.MOUSEDOWN);");
	PlayerWin.document.writeln("window.onmousedown = function(e){");
	PlayerWin.document.writeln("if(e.target==document)return false;");
	PlayerWin.document.writeln("}");
	PlayerWin.document.writeln("}");
	PlayerWin.document.writeln("else {");
	PlayerWin.document.writeln("document.onmousedown = function(){return false}");
	PlayerWin.document.writeln("}");
	PlayerWin.document.writeln("</script>");
	PlayerWin.document.writeln("</head>");
    PlayerWin.document.writeln("<body bgcolor='#c60000'>"); //  onload = closeMe(); self.focus() nanti ditulis di body specify background img if desired
    PlayerWin.document.writeln("<div align='center'>");
    PlayerWin.document.writeln("<font color='#FFFFFF' size='4'>" + filedesc + "</font><br />");
	PlayerWin.document.writeln("<font color='#FFFFFF' size='2'>" + artis + " - " + judul + "</font><br />");
    PlayerWin.document.writeln("<object type='application/x-shockwave-flash' data='http://www.telkomsel.com/web/template/default/id/include/swf/player.swf' id='audioplayer1' height='24' width='290'><param name='movie' value='http://www.telkomsel.com/web/template/default/id/include/swf/player.swf'><param name='FlashVars' value='playerID=1&amp;soundFile=" + filepath + "'><param name='quality' value='high'><param name='menu' value='false'><param name='wmode' value='transparent'></object>");
    //PlayerWin.document.writeln("<form><div align='center'><input type='button' value='Close this window' onclick='javascript:window.close();'></div></form>");
    //PlayerWin.document.writeln(filedesc);
    //PlayerWin.document.writeln(filepath);
    PlayerWin.document.writeln("</body></html>");

    PlayerWin.document.close(); // "Finalizes" new window
}