/*-------------------------------------------------------------------
 General stuff
-------------------------------------------------------------------*/

function gid(name) {
	return document.getElementById(name);
}

/*-------------------------------------------------------------------
Player javascript API
-------------------------------------------------------------------*/
var play_one=false;
var play_random=false;
var get_current_song=0;
var current_song=0;
var playlist_length=0;

function sendEvent(swf,typ,prm) { 
	thisMovie(swf).sendEvent(typ,prm); 
	
};

function getUpdate(typ,pr1,pr2,swf) {
		if(typ == "item" && swf == "jstest3"){
		        gid('current_vitri').innerHTML = pr1;
		        hilightCurrentItem(pr1);
		        current_song=pr1;
		    }
		if(typ == "state" && swf == "jstest3"){		
		if(pr1==3){ 
		             if(play_one){ sendEvent('jstest3','playitem',get_current_song);   }
		             else  
		                if(play_random){ sendEvent('jstest3','playitem',Math.floor(Math.random()*getLength("jstest3")));   }
		                else
		                    {
		                        var repeat_playlist=getLength("jstest3")-1;
		                        if(repeat_playlist==pr1)sendEvent('jstest3','playitem',0); 
		                    }
                  }		
		}		
};
function loadFile(swf,obj) {
	thisMovie(swf).loadFile(obj); 
	
};
function getLength(swf) { 
	//alert(swf);
	var len = thisMovie(swf).getLength(); 
	 return len;
};
function addItem(swf,obj,idx) {
	//alert(obj);
	thisMovie(swf).addItem(obj,idx);
};
function removeItem(swf,idx) {
	thisMovie(swf).removeItem(idx);
};
function itemData(swf,idx) { 
	var obj = thisMovie(swf).itemData(idx);
	var title_song=new Array();
         title_song[0]= obj["title"];
         title_song[1]= obj["file"];
         title_song[2]= obj["id_song"];
	return title_song;
};
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return ob_flash;//document.getElementById(movieName);
	} else {
		return ob_flash;//document[movieName];
	}
};

/*
    *doc gia tri cua nut radio
    
*/
function getValueRadio(name)
    {   var rad=document.getElementsByName(name);
        for (i=0;i<rad.length;i++){
        if (rad[i].checked==true)
            return rad[i].value;
    }
    }
    //set value radio
  function setCheckedValue(name,newValue) {
	var rad=document.getElementsByName(name);
	var radioLength=rad.length;
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
    //play mode

    function playMode(){
		 if(getValueRadio("tuychon")==1){
			play_one=true;
			play_random=false;
			get_current_song=current_song-1;
		   }else if(getValueRadio("tuychon")==2){
				play_one=false;
				play_random=true;
			}else{
				play_one=false;
				play_random=false;
			}

    }

 //   playMode();