
var req;
	function loadXMLDoc(url) 
	{
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
		}
	}
	
	
	function processReqChange() 
	{
		if (req.readyState == 4) // only if req shows "complete"
		{
			if (req.status == 200) // only if "OK"
			{
				response  = req.responseXML.documentElement;
				A_Method  =	response.getElementsByTagName('method')[0].firstChild.data;
				A_Result    = response.getElementsByTagName('result')[0].firstChild.data;
				if (A_Method!='addNew')
				{
					eval(A_Method + '(\'\', A_Result)');
				}
				else
				{
					eval(A_Method + '(\'\',\'\', A_Result)');
				}
			} 
			else 
			{
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		}
	}
  
function CreateObject(){
 var http;
 var browser = navigator.appName; 
 if(browser == "Microsoft Internet Explorer"){
	http = new ActiveXObject("Microsoft.XMLHTTP");
 }else{
	http = new XMLHttpRequest();
	}
  return http;
}
var xmlhttp = CreateObject();
if(!xmlhttp) alert('Sorry we can not creat an ActiveX on your browser');
  
function loading(show,type) {
	xmlhttp.open("GET", show, true);
	switch(type){
	case 'main':xmlhttp.onreadystatechange = function (){div_address_is('dnp_list');}
	break;
	
	case 'play':xmlhttp.onreadystatechange = function (){div_address_is('play');}
	break;
	
	case 'list':xmlhttp.onreadystatechange = function (){div_address_is('dnp_song_list');}
	break;
	
	case 'rating':xmlhttp.onreadystatechange = function (){div_address_is('ratesong');}
	break;
	
    case 'broken':xmlhttp.onreadystatechange = 	function (){div_address_is('broken_link');}
	break;
	
	case 'approval':xmlhttp.onreadystatechange = function (){div_address_is('song_approval');}
	break;
	
	case 'comment':xmlhttp.onreadystatechange = function (){div_address_is('comment_list');}
	break;
	
	case 'make_artist':xmlhttp.onreadystatechange = function (){div_address_is('make_artist');}
	break;
	
	case 'add_link_hint':xmlhttp.onreadystatechange = function (){div_address_is('add_link_hint');}
	break;
	
	case 'random_artist_list':xmlhttp.onreadystatechange = function (){div_address_is('random_artist_div');}
	break;
	
	case 'quick_list':xmlhttp.onreadystatechange = function (){div_address_is('quick_list');}
	break;
	
	case 'recommendation':xmlhttp.onreadystatechange = function (){div_address_is('recommendation');}
	break;
	
	case 'artist_dropbox':xmlhttp.onreadystatechange = function (){div_address_is('artist_list');}
	break;
	
	case 'above_adminqp':xmlhttp.onreadystatechange = function (){div_address_is('make_artist');}
	break;

	case 'playlist_display':xmlhttp.onreadystatechange = function (){div_address_is('playlist_display');}
	break;
	
	case 'none':xmlhttp.onreadystatechange = function (){div_address_is('none');}
	break;

	case 'three_list':xmlhttp.onreadystatechange = function (){div_address_is('dnp_three_list');}
	break;

	case 'dnp_top_stats':xmlhttp.onreadystatechange = function (){div_address_is('dnp_top_stats');}	
	break;
	
	case 'newestthread':xmlhttp.onreadystatechange = function (){div_address_is('newestthread');}	
	break;	
	
	}

  xmlhttp.send(null);

}

function comment_content()
{
    xmlhttp.open('POST', 'musicajax.php?do=submit_comment');
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1;');

    var form     		= 	document.forms['dnp_comment'];
    var message_plain 	= 	encodeURIComponent(form.comment_msg.value.replace(/\+/g, "&#43;"));
	var message			= 	encodeURIComponent(message_plain);
	var songid 			=  	encodeURIComponent(form.songid.value);
	var songname 		=  	encodeURIComponent(form.songname.value.replace(/\+/g, "&#43;"));
	var username 		=  	encodeURIComponent(form.username.value.replace(/\+/g, "&#43;"));	
	var userid 			=  	encodeURIComponent(form.userid.value);	
    qstr = 'message=' +message+'&songid=' + escape(songid)+ '&songname='+songname+'&userid=' +escape(userid)+ '&username='+username; 

    xmlhttp.send(qstr);
	xmlhttp.onreadystatechange = function (){div_address_is('comment');}
}

function create_artist()
{
    xmlhttp.open('POST', 'musicajax.php?do=make_artist');
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1;');

    var form     		= document.forms['dnp_make_artist'];
	var biography 		= encodeURIComponent(form.biography_content.value.replace(/\+/g, "&#43;"));
	var artistname 		= encodeURIComponent(form.names.value.replace(/\+/g, "&#43;"));
	var artistimage 	= encodeURIComponent(form.image.value.replace(/\+/g, "&#43;"));	
	var artistcountry 	= encodeURIComponent(form.country.value);	
	
	var country_check = document.getElementsByName("country");
	for (i = 0; i < country_check.length; i++)
	{
    if (country_check[i].checked){
     artistcountry = country_check[i].value;
    }
	}
	
	data_sent = "biography="+biography+"&artistname="+artistname+"&artistimage="+artistimage+"&artistcountry="+escape(artistcountry); 

    xmlhttp.send(data_sent);
	xmlhttp.onreadystatechange = function (){div_address_is('make_artist');}
}

function save_edit_artist()
{
    xmlhttp.open('POST', 'musicajax.php?do=save_edit_artist');
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1;');

    var form     		= document.forms['dnp_edit_artist'];
	var biography 		= encodeURIComponent(form.biography_content.value.replace(/\+/g, "plus"));
	var artistname 		= encodeURIComponent(form.names.value.replace(/\+/g, "plus"));
	var artistimage 	= encodeURIComponent(form.image.value.replace(/\+/g, "plus"));	

	var country_check = document.getElementsByName("country");
	for (i = 0; i < country_check.length; i++)
	{
    if (country_check[i].checked){
     artistcountry = country_check[i].value;
    }
	}

	var artistid 		= form.artistid.value;

	data_sent = "biography="+biography+"&artistname="+artistname+"&artistimage="+artistimage+"&artistcountry="+escape(artistcountry)+"&artistid="+artistid; 

    xmlhttp.send(data_sent);
	xmlhttp.onreadystatechange = function (){div_address_is('make_artist');}
}

function div_address_is(my_name_is){
	if(xmlhttp.readyState == 1 || xmlhttp.readyState == 2){show_Loading();
   }else if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
	
	if(
		(my_name_is!='dnp_song_list')
	 && (my_name_is!='dnp_three_list')
	 && (my_name_is!='recommendation')
	 && (my_name_is!='ratesong')
	 && (my_name_is!='broken_link')
	 && (my_name_is!='comment_list')
	 && (my_name_is!='comment')
	 && (my_name_is!='newestthread')
	 && (my_name_is!='quick_list')
	 && (my_name_is!='random_artist_div')	 
	 && (my_name_is!='add_link_hint')		 
	){smoothScroll(my_name_is);}
		
		
		document.getElementById(my_name_is).innerHTML = xmlhttp.responseText;hide_Loading();initLytebox();}  
}

function musicsearch(page,value){
	var key = document.getElementById("key").value;
	if(key.length>2){loading('musicajax.php?&do=musicsearch&type='+value+'&musicquery='+encodeURIComponent(key)+'&page='+page+'','main');} else { alert('There must be more than 3 keywords to search');}
}

function album(page){loading('musicajax.php?do=album&page='+page,'main');}
function viewalbum(albumid){loading('musicajax.php?do=viewalbum&id='+albumid,'main');}
function viewcat(catid,page,type){loading('musicajax.php?do=getdatcat&id='+catid+'&page='+page+'&type='+type,'main');}
function viewartist(artistid,page){loading('musicajax.php?do=viewartist&id='+artistid+'&page='+page,'main');}
function viewbroken(){loading('musicajax.php?do=viewbrokenlinks&#','above_adminqp');}
function viewunapproved(){loading('musicajax.php?do=viewunapprovedlinks&#','above_adminqp');}
function play(id,page){loading('musicajax.php?do=play&song='+id+'&page='+page,'play');}
function playall(id,type){loading('musicajax.php?do=playall&id='+id+'&type='+type,'play');}
function load_dnp_song_list(type,page){loading('musicajax.php?do=dnp_song_list&id='+type+'&page='+page,'list');}
function ratesong(id,mood){loading('musicajax.php?do=ratesong&song='+id+'&mood='+mood,'rating');}
function report_broken(id){loading('musicajax.php?do=report_broken&id='+id,'broken');}
function approve_song(id){loading('musicajax.php?do=approve_song&id='+id,'approval');}
function kill_song(id){loading('musicajax.php?do=kill_this_song&id='+id,'approval');}
function rate_comment(id,songid,rate){loading('musicajax.php?do=rate_comment&id='+id+'&songid='+songid+'&rate='+rate,'comment');}
function view_comment(id,page){loading('musicajax.php?do=view_comment&id='+id+'&page='+page,'comment');}
function kill_comment(id,songid){onDimBG();if(confirm('Warning! This comment will be removed permantly from database. Confirm? ')){loading('musicajax.php?do=kill_this_comment&id='+id+'&songid='+songid,'comment');offDimBG();}else{offDimBG();return false;}}
function make_artist(){loading('musicajax.php?do=make_artist','make_artist');}
function edit_artist(id){loading('musicajax.php?do=edit_artist&id='+id,'make_artist');}
function delete_artist(id,confirm_action){loading('musicajax.php?do=delete_artist&id='+id+'&confirm_action='+confirm_action,'make_artist');}
function add_link(type){loading('musicajax.php?do=add_link_hint&type='+type,'add_link_hint');
var dnp_add_media = document.forms['dnp_add_media'];
if(type!=null){dnp_add_media.type.options[2].selected=true;}else{dnp_add_media.type.options[0].selected=true;}}
function random_artist_list(){loading('musicajax.php?do=make_random_artist_list','random_artist_list');}
function quick_list(){loading('musicajax.php?do=make_quick_list&#','quick_list');}
function recommendation(id,catid){loading('musicajax.php?do=make_recommendation&id='+id+'&catid='+catid,'recommendation');}
function view_artist_dropbox(order){loading('musicajax.php?do=view_artist_dropbox&order='+order,'artist_dropbox');}
function add_a_media_playlist(id){loading('musicajax.php?do=add_ajax_playlist&id='+id,'playlist_display');}
function get_media_playlist(page){loading('musicajax.php?do=get_ajax_playlist&page='+page,'playlist_display');}
function delete_media_playlist(id){loading('musicajax.php?do=delete_ajax_playlist&id='+id,'playlist_display');}
function view_shared_playlist(){loading('musicajax.php?do=view_shared_playlist','main');}
function sharepl(action){loading('musicajax.php?do=share_playlist&action='+action,'none');}
function view_sharedpl(userid){loading('musicajax.php?do=view_other_playlist&userid='+userid,'main');}
function view_three_list(){loading('musicajax.php?do=view_three_list','three_list');}

function make_the_newestthread_list(limit,type,moreorless){loading('musicajax.php?do=newthread&limit='+limit+'&orderby='+type+'&moreorless='+moreorless,'newestthread');}


function show_my_playlist(){
		get_media_playlist();
		document.getElementById("playlist_button").style.display = 'none';	
}

function post_article_type(type){
	if(type=='article'){
		document.getElementById("song_url").disabled = true;
		document.getElementById("performer_not_for_article").disabled = true;
		document.getElementById("album_not_for_article").disabled = true;
		document.getElementById("guide_not_for_article").disabled = true;
		document.getElementById("normallink_guide").style.visibility = "hidden";
	}else{
		document.getElementById("song_url").disabled = false;
		document.getElementById("performer_not_for_article").disabled = false;
		document.getElementById("album_not_for_article").disabled = false;
		document.getElementById("guide_not_for_article").disabled = false;
		document.getElementById("normallink_guide").style.visibility = "visible";	
	}
}

function checkbox_ratesong(checkboxname,id){
  if( document.getElementById('checkbox_rating').checked == 1){
   ratesong(id,"like");
  }else{
   ratesong(id,"dislike");}
}

function checkbox_sharepl(){
  if( document.getElementById('checkbox_sharing').checked == 1){
	sharepl("1");
  }else{
	sharepl("0");}
}
function close_3_list(){document.getElementById("dnp_three_list").innerHTML = "";}
function close_make_artist(){document.getElementById("make_artist").innerHTML = "";}
function close_music(){document.getElementById("play").innerHTML = "";}
function close_mresult(){document.getElementById("dnp_list").innerHTML = "";}
function close_songlist(){document.getElementById("dnp_song_list").innerHTML = "";}
function close_playlist(){document.getElementById("playlist_display").innerHTML = "";document.getElementById("playlist_button").style.display = 'block';}

function close_comment(){document.getElementById("comment_block").style.display = "none";document.getElementById("switch_comment_on").style.display = "block";}
function show_comment(){document.getElementById("comment_block").style.display = "block";document.getElementById("switch_comment_on").style.display = "none";}
function offDimBG(){document.getElementById("dimBG").style.display = "none";}
function onDimBG(){document.getElementById("dimBG").style.display = "block";}
function offajaxWait(){document.getElementById("loader_container").style.display = "none";}
function onajaxWait(){document.getElementById("loader_container").style.display = "block";}
function sample_into_urlbox(sample){document.getElementById("song_url").value = sample;}


function del(id){
onDimBG();
if(confirm('Warning! This song will be removed permantly from database. Confirm? ')){ kill_song(id);offDimBG();alert("Task has been completed!");}else{offDimBG();return false;}}

//Flying Loading box of NDK script.
//It's pretty cool
var ie45,ns6,ns4,dom;
if (navigator.appName=="Microsoft Internet Explorer") ie45=parseInt(navigator.appVersion)>=4;
else if (navigator.appName=="Netscape"){  ns6=parseInt(navigator.appVersion)>=5;  ns4=parseInt(navigator.appVersion)<5;}
dom=ie45 || ns6;

var timershow=false;
var curx=-200;
var cury=200;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  win_w = window.innerWidth;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  win_w = document.body.offsetWidth;
 }
}

var mid_w=win_w/2;


function getobj(id) {
el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
return el;
}

function moveobj(obj,x,y) {obj.style.left=x + "px";obj.style.top=y+ "px";curx=x;cury=y;}

function stayMiddle() {
	if (document.documentElement && document.documentElement.scrollTop)
		var pY =  document.documentElement.scrollTop;
	else if (document.body)
		var pY =  document.body.scrollTop;

	obj = getobj('LoadingDiv');
	newy = cury+((pY-cury)/15)+15;
	moveobj(obj,curx, newy);
}

function nshow() {obj = getobj('LoadingDiv');newx = curx+((mid_w-curx)/2)-25;moveobj(obj,newx, cury);}
function nhide() {obj = getobj('LoadingDiv');newx = curx+((0-curx)/16)-15;moveobj(obj,newx, cury);}
// End of Flying Loading Box


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;

    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	if(opacity==2){object.display = 'none';}
} 

function currentYPosition() {
	if (self.pageYOffset)
		 return self.pageYOffset;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (document.body.scrollTop)
		 return document.body.scrollTop;
	return 0;
}
function elmYPosition(eID) {
	var elm  = document.getElementById(eID);
	var y    = elm.offsetTop;
	var node = elm;
	while (node.offsetParent && node.offsetParent != document.body) {
		node = node.offsetParent;
		y   += node.offsetTop;
	} return y;
}
function smoothScroll(eID) {
	var startY   = currentYPosition();
	var stopY    = elmYPosition(eID);
	var distance = stopY > startY ? stopY - startY : startY - stopY;
	if (distance < 100) {
		scrollTo(0, stopY); return;
	}
	var speed = Math.round(distance / 100);
	var step  = Math.round(distance / 25);
	var leapY = stopY > startY ? startY + step : startY - step;
	var timer = 0;
	if (stopY > startY) {
		for ( var i=startY; i<stopY; i+=step ) {
			setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
			leapY += step; if (leapY > stopY) leapY = stopY; timer++;
		} return;
	}
	for ( var i=startY; i>stopY; i-=step ) {
		setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
		leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
	}
}

