function postSongComment(trk_id){
    var trk = trk_id;
    var username = document.getElementById('username').value;
    var email = document.getElementById('email').value;
    var comment = document.getElementById('comment').value;
    
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/ajax.php?a=songcomment&rnd="+randnum1+"&username="+username+"&email="+email+"&comment="+comment+"&t="+trk, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText != ""){
                alert(xmlhttp.responseText);
            }
                if(xmlhttp.responseText == "Thank you for your comment!"){
                    $('<b>'+username+' writes:</b> '+comment+' <div style="height: 4px;"></div>').prependTo("#comments");
                }
                
            }
        }
    
    xmlhttp.send(null);
    
}

function doRate(trk_id){
    var r = document.getElementById('rating').value;
    var t = trk_id;
    
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/ajax.php?a=ratesong&rnd="+randnum1+"&r="+r+"&t="+t, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText != ""){
                alert(xmlhttp.responseText);
            }
        }
    }
    
    xmlhttp.send(null);
    return false;
}

function doSongUpdate(serverad, portno){
    ajaxpage("http://www.webradiocentral.com/scripts.php?a=np_ajax&s="+serverad+"&p="+portno, "now_playing");
}

function removeStation(station_id, row_id){
    var randnum1 = Math.floor(Math.random()*1000000);

    xmlhttp.open("GET", "/ajax.php?a=removest&r="+randnum1+"&remove="+station_id, true);
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            if (xmlhttp.responseText == "OK"){
                //loadComments(media_type, media_id, page_num);
                document.getElementById(row_id).style.display = 'none';
            }
            else if(xmlhttp.responseText == ""){
                alert("Error processing request. Please try again.");
            }
            else{
                alert(xmlhttp.responseText);
            }
        }
    }
    
    xmlhttp.send(null);
}

function wmHelp(){
    parent.location = '/wmhelp.php';
    parent.focus();
}

function tuneIn(station_hash,prem_stat){
    if(prem_stat == 1){
    var tuneInBox = window.open('/tune-in.php?h='+station_hash, 'tuneIn', 'width=432,height=336,scrollbars=yes');
    tuneInBox.outerWidth = 432;
    tuneInBox.focus();
    }
    else{
        var tuneInBox = window.open('/tune-in.php?h='+station_hash, 'tuneIn', 'width=740,height=336,scrollbars=yes');
        tuneInBox.outerWidth = 740;
    tuneInBox.focus();
        }
}

function supportEmail(){
    document.write('<a href="mailto:suppo'+'rt@webradiocentr'+'al.com">suppo'+'rt@webradiocentr'+'al.com</a>');
}

function highlightCell(elementid){
    document.getElementById(elementid).className = 'prem_box_over';
}

function resetCell(elementid, origClass){
    document.getElementById(elementid).className = origClass;
}

// Check username availability
function checkUsername(){
    var randnum = Math.floor(Math.random()*1000000);
    ajaxpage("/ajax.php?a=checkusername&r="+randnum+"&username="+document.getElementById('username').value, "username_result");
}

// AJAX Retrieval
var previouscontent = "";
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))

if(document.getElementById(containerid).innerHTML != page_request.responseText){
document.getElementById(containerid).innerHTML = page_request.responseText;
}

}

// Send AJAX Command
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
