
var d = document;

function SetRadio(typeRadio){
    switch (typeRadio)
    {
        case '0':
	        window.open(powerHostName + 'PowerRadio.aspx', 'radioPopUp', 'width=400,height=228,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=200');  
	        break;
        case '1':
	        window.open(powerHostName + 'PowerRadioFlogao.aspx', 'radioPopUp', 'width=400,height=228,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=200');  
	        break;
	    default:
	        window.open(powerHostName + 'PowerRadio.aspx', 'radioPopUp', 'width=400,height=228,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=200');  
	        break;	       
	}
}

function setPlayer(ligar, varActivatingRadio){	
	var divOn = d.getElementById('btAtivar');
	var divOff = d.getElementById('btDesativar');
	
	if(ligar){		
	    divOn.style.display = 'none';
		divOff.style.display = 'block';
			
	    startPlayer('MediaPlayer');
		
		if (varActivatingRadio != null)
		    alert(varActivatingRadio);
	}
	else{
	    divOn.style.display = 'block';
		divOff.style.display = 'none';
		
		stopPlayer('MediaPlayer');
	}
}

WMPObject = function(id, src, width, height, containerId, autoStart, visible){    
    this.src = src;
	this.id = id;
	
	if (visible != null && ! visible){
	    this.width = 0;
	    this.height = 0;
	}
	else{
	    this.width = width;
	    this.height = height;
	}
    
    this.containerId = containerId;	    
    
    this.params = new Object();

    this.addParam('TYPE', 'application/x-mplayer2');
    this.addParam('PLUGINSPACE', 'http://www.microsoft.com/Windows/MediaPlayer/download/default.asp');
    
    if (autoStart != null && ! autoStart){
        this.addParam('Autostart', '0');
        this.addParam('Autoplay', '0');
    }
    else{
        this.addParam('Autostart', '1');
        this.addParam('Autoplay', '1');
    }
    
    this.addParam("ShowDisplay", "0");      
    this.addParam('ShowControls', '1');
    this.addParam('ShowStatusBar', '1');
    this.addParam('ShowTracker', '1');
    this.addParam("AutoSize", "0");  
    this.addParam("TransparentAtStart", "1");  
    this.addParam("AnimationAtStart", "0");  
    this.addParam("ShowPositionControls", "0");  
    this.addParam("DisplaySize", "0");  
    this.addParam("Volume", "100");  
    this.addParam("StretchToFit", "1");
    this.addParam('AutoRewind', '1');
    this.addParam('Loop', '1');    
}

function addPlayer(id, src, width, height, containerId, autoStart, visible){
    var player = new WMPObject(id, src, width, height, containerId, autoStart, visible);
    player.write();
}

WMPObject.prototype.play = function(){
    startPlayer(this);
}

function startPlayer(player, contentDocument) {    
    if (contentDocument != null) d = contentDocument;
    
    if (typeof(player) == 'string')
        player = d.getElementById(player);        
    else
        player = d.getElementById(player.id);
    
    if (player != null){
        if (navigator.plugins && navigator.plugins.length) // not ie
            player.innerHTML = player.innerHTML.replace('autoplay="0"', 'autoplay="1"').replace('autostart="0"', 'autostart="1"');
        else // ie
            player.firstChild.play();
    }
}

WMPObject.prototype.stop = function(){
    stopPlayer(this);
}

function stopPlayer(player, contentDocument) {    
    if (contentDocument != null) d = contentDocument;
    
    if (typeof(player) == 'string')
        player = d.getElementById(player);
    else
        player = d.getElementById(player.id);

    if (player != null){
        if (navigator.plugins && navigator.plugins.length) // not ie
            player.innerHTML = player.innerHTML.replace('autoplay="1"', 'autoplay="0"').replace('autostart="1"', 'autostart="0"');
        else // ie
            player.firstChild.stop();
    }
}

WMPObject.prototype.getHTML = function(){
    var WMPHTML = "<div id='" + this.id + "'>";
    
    if (navigator.plugins && navigator.plugins.length) { // not ie
        WMPHTML += '<embed type="application/x-mplayer2" src="' + this.src + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + 'player"';
    }
    else { // pc ie
        WMPHTML += '<embed width="' + this.width + '" height="' + this.height + '" id="' + this.id + 'player" ';
        this.addParam("src", this.src);            
    }
    
    for (var param in this.getParams()) {
        WMPHTML += ' ' + param + '="' + this.getParam(param) + '"';
    }
    WMPHTML += '></embed></div>';
    
    return WMPHTML;
} 

WMPObject.prototype.write = function(){
    if (this.containerId != null){
        var containerObject = d.getElementById(this.containerId);
        
        if (containerObject != null){
            containerObject.innerHTML = this.getHTML();
            return;
        }
    }
    
    d.write(this.getHTML());        
}

WMPObject.prototype.addParam = function(name, value) {
    this.params[name] = value;
}

WMPObject.prototype.getParams = function() {
    return this.params;
}

WMPObject.prototype.getParam = function(name) {
    return this.params[name];
}

WMPObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += param + '="' + this.getParam(param) + '" ';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

function closeRadioPage(){
	var divOn = d.getElementById('btAtivar');
	var divOff = d.getElementById('btDesativar');
	divOn.style.display = 'block';
	divOff.style.display = 'none';

	document.getElementById('radioOnLine').src='';
}
function openRadioPage(){
	var divOn = d.getElementById('btAtivar');
	var divOff = d.getElementById('btDesativar');
	divOn.style.display = 'none';
	divOff.style.display = 'block';
	document.getElementById('radioOnLine').src='http://'+document.domain+'/radioPage.htm';
}

function addAutoPlayer(id, src, width, height, containerId, autoStart, visible){
    var player = new WMPObject(id, src, width, height, containerId, autoStart, visible);
    player.write();	
}

var windowRadio;
function closePowerRadioPage(){
	var divOn = document.getElementById('btAtivar');
	var divOff = document.getElementById('btDesativar');
	divOn.style.display = 'block';
	divOff.style.display = 'none';
	try{
		windowRadio.close();
	}catch(e){}
}
function openPowerRadioPage(){
	var divOn = document.getElementById('btAtivar');
	var divOff = document.getElementById('btDesativar');
	divOn.style.display = 'none';
	divOff.style.display = 'block';
	windowRadio =	window.open('http://www.power.com/Pub/PowerRadio.aspx', 'PowerRadioPopUp', 'width=425,height=225,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=200');  
}