//var xml;
var result;
var playid;
var defaultview = "";
var busy = 0;
var task_run = 0;
var errorcount = 0;
var flash_w = 484;
var flash_h = 418;
var vidata = Array();
var quotecount = 0;
var tmpquote = new Array();
var intval = "";
var uagent = navigator.userAgent.toLowerCase();
var is_iphone  = (uagent.indexOf('iphone') != -1);
var is_firefox  = (uagent.indexOf('firefox') != -1);
var is_chrome  = (uagent.indexOf('chrome/1') != -1);
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );
function httpRequest(url,target,handle,qry) {
	var xml;
    if (typeof XMLHttpRequest == 'undefined') {
        objects = Array(
            'Microsoft.XmlHttp',
            'MSXML2.XmlHttp',
            'MSXML2.XmlHttp.3.0',
            'MSXML2.XmlHttp.4.0',
            'MSXML2.XmlHttp.5.0'
        );
        for (i = 0; i < objects.length; i++) {
            try {
                xml = new ActiveXObject(objects[i]);
            } catch (e) {}
        }
    } else {
        xml = new XMLHttpRequest();
    }
    xml.open('post', url, true);
    xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //result = document.getElementById(target);
    //busy = 1;
    if (handle) {
		result = target;
        xml.onreadystatechange = eval(handle);
    } else {
        xml.onreadystatechange = function() {
            if (xml.readyState == 4) {
				if(target == "Esnips") {
					ES(xml.responseText);
					return false;
				}
				var js_check = xml.responseText.match(/<script>(.*)<\/script>/g);
				if (js_check) {
					for(i = 0; i < js_check.length; i++) {
						var newjs = js_check[i].replace(/<script>/, "");
						newjs = newjs.replace(/<\/script>/, "");
						eval(newjs);
					}
				}
                document.getElementById(target).innerHTML = xml.responseText;
                //busy = 0;
            } else {
				if(target == "Esnips" || target == "4Shared" || target == "MP3Realm" || target == "Tagoo" || target == "wrzuta") {
					document.getElementById(target).innerHTML = "<div class='title'><span>" + target + "</span></div><div style='padding-top:5px'><img src='/images/load.gif' align='absmiddle'>Loading...</div>";
				}
			}
        }
    }
    xml.send(qry);
	return false;
}
function CheckAll() {
	var fmobj = document.forms['opt'];
	for (var i=0; i<fmobj.elements.length; i++) {
		var e = fmobj.elements[i];
		if ((e.name != 'checkall') && (e.type == 'checkbox') && (!e.disabled) && (e.value)) {
			e.checked = fmobj.elements['checkall'].checked;
		}
	}
}
function multi_page_jump( url_bit, current, total_posts, loc ) {
	msg = "Please enter a page number to jump to between 1 and " + total_posts;
	userPage = prompt( msg, '' );
	if ( userPage > 0  && userPage != current) {
		//window.location = url_bit + "/" + userPage + "/";
		httpRequest(url_bit + "/page/" + userPage + "/", loc);
	}
}
function getcookie( name )
{
	var cname = name + '=';
	var cpos  = document.cookie.indexOf( cname );
	if ( cpos != -1 )
	{
		var cstart = cpos + cname.length;
		var cend   = document.cookie.indexOf(";", cstart);
		if (cend == -1)
		{
			cend = document.cookie.length;
		}
		return unescape( document.cookie.substring(cstart, cend) );
	}
	return null;
}
function setcookie( name, value, sticky )
{
	var expire = "";
	var domain = "";
	var path   = "/";
	if ( sticky )
	{
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	document.cookie = name + "=" + value + "; path=" + path + expire + domain + ';';
}
function showhide(d) {
	var target;
	var item = d.split(',');
	for (var i=0; i<item.length; i++) {
		target = document.getElementById(item[i]);
		if(target) {
			if(target.style.display == 'none') {
				target.style.display = '';
			} else {
				target.style.display = 'none';
			}
		}
	}
}
function preview(url,target) {
    url = unescape(url);
    var path = url.split("/");
    if(path[0] == "doc") {
        var _loc1 = new Date();
        var code = _loc1.getTime();
		if(url.substr(url.lastIndexOf('.'),4).toLowerCase() == ".wma" || url.substr(url.lastIndexOf('.'),4).toLowerCase() == ".wav") {
			ShowMedia("http://www.esnips.com/nsdoc/"+ path[1] + "/?id=" + code, target, 270, 44);
			return false;
		}
        url = "http://www.esnips.com/nsdoc/" + path[1] + "/ts_id/" + code + "/ns_flash/file88.mp3";
		if(is_iphone) {
			if(document.getElementById(playid)) document.getElementById(playid).innerHTML = "";
			var ihtml = "<object type=\"audio/mpeg\" data=\"" + url + "\" width=\"250\" height=\"16\">";
				ihtml += "<param name=\"autoplay\" value=\"true\" />";
				ihtml += "<param name=\"src\" value=\"" + url + "\" />";
				ihtml += "<object classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"250\" height=\"16\">";
				ihtml += "<param name=\"autostart\" value=\"true\" />";
				ihtml += "<param name=\"url\" value=\"" + url + "\" />";
				ihtml += "<param name=\"showcontrols\" value=\"true\" />";
				ihtml += "<param name=\"volume\" value=\"100\" />";
				ihtml += "</object></object>";
    		if(document.getElementById( target )) {
        		document.getElementById( target ).innerHTML = ihtml;
    		} else {
        		document.write( ihtml );
    		}
			playid = target;
			return false;
		}
		if(!is_firefox) {
			ShowMedia(url, target, 270, 44);
			return false;
		}
    }
	if(is_iphone) {
		if(document.getElementById(playid)) document.getElementById(playid).innerHTML = "";
		var ihtml = "<object type=\"audio/mpeg\" data=\"" + url + "\" width=\"250\" height=\"16\">";
			ihtml += "<param name=\"autoplay\" value=\"true\" />";
			ihtml += "<param name=\"src\" value=\"" + url + "\" />";
			ihtml += "<object classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"250\" height=\"16\">";
			ihtml += "<param name=\"autostart\" value=\"true\" />";
			ihtml += "<param name=\"url\" value=\"" + url + "\" />";
			ihtml += "<param name=\"showcontrols\" value=\"true\" />";
			ihtml += "<param name=\"volume\" value=\"100\" />";
			ihtml += "</object></object>";
    	if(document.getElementById( target )) {
        	document.getElementById( target ).innerHTML = ihtml;
    	} else {
        	document.write( ihtml );
    	}
		playid = target;
		return false;
	}
	var player = document.getElementById(target);
	if(player) {
		if(document.getElementById(playid)) document.getElementById(playid).innerHTML = "";
		var fo = new FlashObject("/player.swf", "", "290", "24", 8, "#ffffff");
		fo.addParam("menu", "false");
		fo.addParam("wmode", "transparent");
		fo.addVariable("soundFile", url);
		fo.addVariable("autostart", "yes");
		fo.addVariable("lefticon", "0x990000");
		fo.addVariable("righticon", "0x990000");
		fo.write(target);
		playid = target;
	}
}
function ShowMedia(url,target,width,height) {
    if(document.getElementById(playid)) document.getElementById(playid).innerHTML = "";
    var Fhtml = "";
	if(is_iphone) {
		Fhtml = "<object type=\"audio/mpeg\" data=\"" + url + "\" width=\"250\" height=\"16\">";
		Fhtml += "<param name=\"autoplay\" value=\"true\" />";
		Fhtml += "<param name=\"src\" value=\"" + url + "\" />";
		Fhtml += "<object classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"250\" height=\"16\">";
		Fhtml += "<param name=\"autostart\" value=\"true\" />";
		Fhtml += "<param name=\"url\" value=\"" + url + "\" />";
		Fhtml += "<param name=\"showcontrols\" value=\"true\" />";
		Fhtml += "<param name=\"volume\" value=\"100\" />";
		Fhtml += "</object></object>";
	} else if(is_safari && !is_chrome) {
	    Fhtml += '<embed src="'+url+'" width="'+width+'" height="22" loop="false" autoplay="true" controller="true" border="0" type="video/quicktime" kioskmode="true" scale="tofit" pluginspage="http://www.apple.com/quicktime/download/"></embed>';
	} else if(is_firefox) {
	//if(is_firefox) {
    	Fhtml += '<object width="'+width+'" height="'+height+'" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
    	Fhtml += '<param name="URL" value="'+url+'">';
    	Fhtml += '<param name="playCount" value="1">';
    	Fhtml += '<param name="autoStart" value="-1">';
    	Fhtml += '<param name="uiMode" value="full">';
    	Fhtml += '<param name="stretchToFit" value="1">';
    	Fhtml += '<param name="enabled" value="-1">';
    	Fhtml += '<embed width="'+width+'" height="'+height+'" src="'+url+'" playCount="1" AutoStart="true" uiMode="full" stretchToFit="1" enabled="1"></embed>';
    	Fhtml += '</object>';
	} else {	
		Fhtml +='<object id="wmaplayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+width+'" height="'+height+'">' +
				'<param name="url" value="'+url+'" /> ' +
				'<param name="autoStart" value="true" /> ' +
				'<param name="showControls" value="true" /> ' +
				'<param name="rate" value="1">' +
				'<param name="balance" value="0">' +
				'<param name="currentPosition" value="0">' +
				'<param name="playCount" value="1">' + 
				'<param name="currentMarker" value="0">' +
				'<param name="invokeURLs" value="-1">' + 
				'<param name="volume" value="100">' +
				'<param name="mute" value="0">' +
				'<param name="uiMode" value="full">' +
				'<param name="stretchToFit" value="0">' +
				'<param name="windowlessVideo" value="1">' +
				'<param name="enabled" value="-1">' +
				'<param name="fullScreen" value="0">' +
				'<param name="enableErrorDialogs" value="0">' +			  
				'</object>';
	}
    if(document.getElementById( target )) {
        document.getElementById( target ).innerHTML = Fhtml;
    } else {
        document.write( Fhtml );
    }
	playid = target;
}
function eload(url) {
    url = unescape(url);
    var path = url.split("/");
    var _loc1 = new Date();
    var code = _loc1.getTime();
    url = "http://www.esnips.com/nsdoc/" + path[1] + "/ts_id/" + code + "/ns_flash/file88.mp3";
    window.location.href = url;
}
function ES(txt) {
    var _loc1 = new Date();
    var code = _loc1.getTime();
	var eid_check = txt.match(/ts_id\/([0-9]+)/g);
    if (eid_check) {
        for (i = 0; i < eid_check.length; i++) {
			//alert(eid_check[i]);
            txt = txt.replace(eid_check[i], "ts_id/"+code);
        }
    }
	document.getElementById('Esnips').innerHTML = txt;
}
function pupp(url) {
	window.open(unescape(url), "esn", "toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=320,height=70");
}
function closeDIV() {
	if(document.getElementById(playid)) document.getElementById(playid).innerHTML = "";
}
function goHome() {
	window.location.href = "http://mp3.azn.me/";
}
function redirect(url) {
	if(is_chrome) {
		window.location.replace(unescape(url));return false;
	} else if(is_firefox) {
		window.location.href = '/redirect.php?'+unescape(url);return false;
	} else {
		window.location.href = unescape(url);return false;
	}
}
window.onload = function() {
	var sb = document.getElementById('searchbox');
	if(sb) {
		sb.focus();
		sb.select();
	}
}