/* --------------------------------------------------------------------------
 * CCRTVi Framework v0.2
 * Author: Jabi Suarez
 * 2007/11/05
 * This framework uses prototype.js 1.6, ObjTree.js and Subject.js
 * -------------------------------------------------------------------------- */

var v_tAppDebatActiu=0;
var v_tAppInfo=0;
var v_tAppLastPlayed=0;
var v_tAppLastPlayedReset=0;
var v_tAppPostit=0;
var v_tAppOpina=0;
var v_tAppWebcam=0;
var v_tAppEnquesta=0;
var v_tAppMosca=0;
var v_timestamp=0;
var v_dataTimestamp=0;
var BC_Actual=0;
var idDebat=0;
var idPrograma="0";	//Not "" nor 0, for Programa's update testing purposes
var indexLastSelected=0;
var numBCs=0;
var vIdPubli = 1512642;	//default publi
var vIdDefaultPubli = 1512642;
var vTimerInterval = 10; //seconds
var vTimerIntervalRefresher = 10000;
var vMinimizePostitsDelay = 8;
var vNumberOpinasPlaying=0; //We use this counter to know how many MICRO OBERT audios are we playing
							//If we are playing any audio, we don't update the OPINIONS zone

var	vRefreshMainContent=true;
var vLoged=false;
var vMinimizeNewPostits=true;
var vTraceOn=false;
var vParams="";

var intervRefresher;
var v_urlSU= '/su/Register';
var v_urlRefreher= 'xml_dinamic/refresh_catradio.xml';
var v_urlLastPlayed='xml_dinamic/last_played_catradio.xml';
var vLayoutHome= 'xml/presentacio/layoutHome.xml';
var v_urlTimestamp='/su/time.jsp';
var v_urlItemPrograma='/pcatradio/endirecte/icrItem.jsp?item=programa&idint=';


try{
	vParams = getURLParams(top.location.href,false);
	vTraceOn= vParams['traceOn']=="si"? true : false;
}
catch(error){}

// Functions for Load Layouts, check login and paint all the black
function startApp(){
	InterfaceAgent.CommentsContainerBackup = $('CommentsContainer').innerHTML;
	InterfaceAgent.LiveInterfaceBackup = $('ucarea').innerHTML;
	loadXMLLayout(vLayoutHome);
	try{doAjaxCheckLogin(); }
	catch(error){/*trace ("Error trying to check login");*/}
	loadServerTimestamp();
	vTimerIntervalRefresher= vTimerInterval * 1000; //miliseconds
	loadXMLRefresh();
	stopMinimizeNewPostits.delay(vMinimizePostitsDelay);
	intervRefresher= setInterval("loadXMLRefresh()",vTimerIntervalRefresher);//every 10 seconds
}

function loadServerTimestamp(){
	var v_xmlObjTree = new XML.ObjTree();
	var v_params = {
		method:       "get"
		,parameters:   'type=xml&format=HH-mm-ss-yyyyMMdd&dummy='+Math.random()
	};
	var v_xmlObj= v_xmlObjTree.parseHTTP( v_urlTimestamp, v_params); //sync (needed to continue...)
	try{
		var st= v_xmlObj.data["@actual"];
		var ast= st.split('-');
		var vTime= (parseInt(ast[0])*3600) + (parseInt(ast[1])*60) + (parseInt(ast[2]));
		v_timestamp= Math.floor( vTime / vTimerInterval );
		v_dataTimestamp = ast[3];
	}
	catch (error){v_timestamp=0;}
	//trace(v_timestamp);
}

function stopMinimizeNewPostits(){
	trace("stopMinimizeNewPostits");
	vMinimizeNewPostits=false;
}

function startMinimizeNewPostits(){
	trace("startMinimizeNewPostits");
	vMinimizeNewPostits=true;
}

/**
 * We use the vNumberOpinasPlaying counter to know how many MICRO OBERT audios are we playing.
 * If we are playing any audio, we don't update the OPINIONS zone. 
 * This is checked in testUpdate function
 * The newMicroObertPlaying and stopMicroObertPlaying are called by the audio players
 * when starts and stops the audio playing
 */
function newMicroObertPlaying(){
	vNumberOpinasPlaying++;
	trace("newMicroObertPlaying(): ara:"+vNumberOpinasPlaying);
}

function stopMicroObertPlaying(){
	if (vNumberOpinasPlaying > 0) {vNumberOpinasPlaying--;}
	trace("stopMicroObertPlaying(): ara:"+vNumberOpinasPlaying);
}

function stopApp(){
	clearInterval(intervRefresher);
}

function restartApp(){
	//alert("restart. Alert per esperar...");
	clearInterval(intervRefresher);
	startMinimizeNewPostits();
	BC_Actual=0;
	v_tAppInfo=0;
	v_tAppLastPlayed=0;
	v_tAppPostit=0;
	v_tAppOpina=0;
	v_tAppWebcam=0;
	v_tAppEnquesta=0;
	v_tAppMosca=0;	
	loadXMLRefresh();
	stopMinimizeNewPostits.delay(vMinimizePostitsDelay);
	intervRefresher= setInterval("loadXMLRefresh()",vTimerIntervalRefresher);
}

// Loads the Layout.xml
function loadXMLLayout(pUrlLayout){
	var v_xmlObjTree = new XML.ObjTree();
	var v_params = {
		method:       "get"
	};
	var v_xmlObj= v_xmlObjTree.parseHTTP( pUrlLayout, v_params); //sync (layout needed to continue...)
	initApp(v_xmlObj);
}

// Build all the layout's components
function initApp(p_xmlObj){

	for (var ii= 0; ii< p_xmlObj.mcs.mc.length; ii++){
		var textCode= 'v'+p_xmlObj.mcs.mc[ii]["@uid"]+' = new '+p_xmlObj.mcs.mc[ii]["@format"]+'(\''+p_xmlObj.mcs.mc[ii]["@uid"]+'\');';
		eval(textCode);

		// data
		try{
			if (p_xmlObj.mcs.mc[ii].data != undefined && p_xmlObj.mcs.mc[ii].data!= null){
				var textCodeData= 'v'+p_xmlObj.mcs.mc[ii]["@uid"]+'.data = \''+p_xmlObj.mcs.mc[ii].data+'\'';
				eval(textCodeData);
			}
		}
		catch(error){
			//trace('ERROR initApp insert data ');
			//nothing to do at this time...
		}

	}

	//Now, adding the observers
	for (var ii= 0; ii< p_xmlObj.mcs.mc.length; ii++){
		try{
			if (p_xmlObj.mcs.mc[ii].notify != undefined && p_xmlObj.mcs.mc[ii].notify!= null && p_xmlObj.mcs.mc[ii].notify.length > 0){
				var textCodeObservers= 'v'+p_xmlObj.mcs.mc[ii]["@uid"]+'.observers = new Subject();';
				eval(textCodeObservers);

				if(!isArray(p_xmlObj.mcs.mc[ii].notify)){
					var addObserverCode= 'v'+p_xmlObj.mcs.mc[ii]["@uid"] +'.observers.addObserver(v'+p_xmlObj.mcs.mc[ii].notify+');';
					eval(addObserverCode);
				}
				else{
					for (var jj=0; jj< p_xmlObj.mcs.mc[ii].notify.length; jj++){
						var addObserverCode= 'v'+p_xmlObj.mcs.mc[ii]["@uid"] +'.observers.addObserver(v'+p_xmlObj.mcs.mc[ii].notify[jj]+');';
						eval(addObserverCode);
					}
				}
			}
		}
		catch(error){
			trace('ERROR adding observers' +ii);
			trace(error);
		}

	}

}
// ####################################################################
// Functions for Refresh Data
function loadXMLRefresh(){
	v_timestamp++;
	var v_xmlObjTree = new XML.ObjTree();
	var v_params = {
		method:       "get"
		,parameters: 'dummy='+v_dataTimestamp+''+v_timestamp
	};
	var v_xmlObj= v_xmlObjTree.parseHTTP( v_urlRefreher, v_params, testUpdate ); //async
}

function testUpdate(p_xmlObj)
{
	// Test for actual debate change
	unaryTestUpdate("v_tAppDebatActiu", p_xmlObj, 'CR_ED_PRGDEB', updateIdDebat);

	// Test for actual song change
	unaryTestUpdate("v_tAppInfo", p_xmlObj, 'info', notifyInfoObservers);

	// Test for last played songs change
	unaryTestUpdate("v_tAppLastPlayed", p_xmlObj, 'played', notifyLastPlayedObservers, v_urlLastPlayed);

	// Test for new postits
	unaryTestUpdate("v_tAppPostit", p_xmlObj, 'CR_ED_POSTIT', notifyPostitObservers);

	// Test for new opina, only if we aren't playing any MICRO OBERT's audio
	if (vNumberOpinasPlaying ==0){
		unaryTestUpdate("v_tAppOpina", p_xmlObj, 'CR_ED_OPINIONS', notifyOpinaObservers);
	}

	// Test for new webcam
	unaryTestUpdate("v_tAppWebcam", p_xmlObj, 'CR_ED_WEBCAM', updateWebcam);

	// Test for new enquesta
	unaryTestUpdate("v_tAppEnquesta", p_xmlObj, 'CR_ED_ENQUESTA', updateEnquestes);
	
	// Test for new mosca
	unaryTestUpdate("v_tAppMosca", p_xmlObj, 'CR_ED_MOSCA', notifyMoscaObservers);	
}

/**
 * loadBCFromList. Util for load last playeds
 *  also used to force load the BC_Actual
 * @param vNumBC:number. The BC's index on last played
 * @param onlyMainContent:boolean (Default true)
 * @param pContinueRefreshing:boolean (Default false)
 */
function loadBCFromList(vNumBC, pContinueRefreshing, onlyMainContent){
	if (onlyMainContent==undefined){onlyMainContent= true;}
	if (pContinueRefreshing==undefined){pContinueRefreshing= false;}
	if (!pContinueRefreshing){stopRefreshMainContent();}
	indexLastSelected= vNumBC;
	trace("Load BC:"+vlastPlayed.data["llistaBCs"][vNumBC]);
	loadUserBC(vlastPlayed.data["llistaBCs"][vNumBC], true, onlyMainContent);
}

/**
 * Preview Item Codes
 * Force to load an item code
 * @param onlyMainContent:boolean (Default true). If true, only loads the main content info
 */
function loadUserBC(vItemCode, onlyMainContent){
	var vXmlObjBC = new XML.ObjTree();
    var xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><mcs><mc id="info" t="USER'+Math.random()+'" url="/pcatradio/endirecte/icrItem.jsp?item=bloc&amp;idint='+vItemCode+'" /></mcs>';
    var p_xmlObjBC = vXmlObjBC.parseXML( xml );
    //BC_Actual= vItemCode; //NOOOOOOO
    //vlastPlayed.data["llistaBCs"][0]= vItemCode; //NOOOOOOO
	//stopRefreshMainContent();
    if (onlyMainContent){
	    unaryTestUpdate("v_tAppInfo", p_xmlObjBC, 'info', loadInfoMainContent);
    }
    else{
    	unaryTestUpdate("v_tAppInfo", p_xmlObjBC, 'info', notifyInfoObservers);
    }
}	

/**
 * @param tAppName: tApp var's name
 * @param xmlData: xml refresher
 * @param uid: actual mc's id
 * @param onSuccess: onSuccess function
 * @param infoXml: OPTIONAL. If !undefined && !'', info xml path 
 * 	Util to force unaryTestUpdate to load actual xml without cache
 * @description: tests if the mc has changed. 
 * 	If true, loads the data xml and calls the onSuccess funtion
 *  If timestamp contains the literal "USER", it changes not the AppTimestamp
 *  If necessary, it changes the BC_Actual global variable
 *  tomcat requests do not use dummy param
 */
function unaryTestUpdate(tAppName, xmlData, uid, onSuccess, infoXml){
	var v_tApp=eval(tAppName);
	try{
		var v_tNow= 0;
		try{ v_tNow= filterByAttribute(xmlData.mcs.mc,'id',uid)[0]["@t"]; if (v_tNow==undefined){throw("Node "+uid+" not found in refresher");}}
		catch(error){v_tNow= 0;}
		if (v_tApp != v_tNow){
			var v_url = ((infoXml==undefined)||(infoXml==''))? filterByAttribute(xmlData.mcs.mc,'id',uid)[0]["@url"] :infoXml;
			//trace("BC_Actual: "+BC_Actual);
			//trace("v_url: "+v_url);
			if (String(v_tNow).indexOf("USER")== -1){
				eval(tAppName+"=v_tNow;"); //v_tApp= v_tNow;
				if (uid == 'info'){	
					BC_Actual=v_url.split("idint=")[1];
					indexLastSelected=0;
				}
			}
			
			var v_params;
			if (v_url.indexOf("pcatradio")== -1){
				v_params = {method: "get", parameters: 'dummy='+v_dataTimestamp+''+v_timestamp};
			}
			else{
				v_params = {method: "get"};
			}

			var v_xmlObjTree = new XML.ObjTree();
			v_xmlObjTree.force_array = ["images", "uc", "comment"];//For gallery, ucs, opina
			var v_xmlObj= v_xmlObjTree.parseHTTP( v_url, v_params, onSuccess ); //async
	
			if (uid == "info"){
				//trace('hit+Publi'); //only in info mc
				updatePubli(vIdPubli);
				ajaxSite_DoHit();		
			}
		}
		else if (uid=="played"){
			// Test for last played reset
			unaryTestUpdate("v_tAppLastPlayedReset", xmlData, 'last_played', notifyLastPlayedObservers, v_urlLastPlayed);
		}
	}
	catch(error){
		trace(error);
	}
}

function notifyInfoObservers(xmlObj){
	vRefresherInfo.observers.notify(xmlObj, 'update');
}

function notifyLastPlayedObservers(xmlObj){
	vRefresherLastPlayed.observers.notify(xmlObj, 'update');
}

function notifyPostitObservers(xmlObj) {
	if(xmlObj!=undefined && xmlObj.postits!=undefined) {
		//valid XML
		vRefresherPostit.observers.notify(xmlObj, 'update');
		//trace("NotifyObservers");
	} else { // Invalid XML, then retry
		v_tAppPostit = 0 ;
		//trace("Set Time Stamp 0 : Retrying to get xml file");
	}
}

function updateWebcam(xmlObj){
	vpostitLayer.updateWebcam(xmlObj);
}

function updateEnquestes(xmlObj){
	vpostitLayer.updateEnquestes(xmlObj);
}

function notifyOpinaObservers(xmlObj){
	vRefresherOpina.observers.notify(xmlObj, 'update');
}

function notifyMoscaObservers(xmlObj){
	vRefresherMosca.observers.notify(xmlObj, 'update');
}

function updateIdDebat(xmlObj){
	vRefresherPrograma.observers.notify(xmlObj, 'update');
}

/**
 * loadInfoMainContent only loads the info in main content
 */
function loadInfoMainContent(xmlObj){
	vdivLlistaUc.update(xmlObj);
}

/**
 * Stop refreshing the main content
 * The liveBar continues refreshing
 */
function stopRefreshMainContent(){
	try{
		vRefresherInfo.observers.removeObserver(vdivLlistaUc);
		vRefreshMainContent=false;
	}
	catch(error){trace(error);}
}

/**
 * Turns on the global refreshing
 * Stops glowing the liveBar
 * Force refresh info in main content
 */
function startRefreshMainContent(){
	try{
		if (!vRefreshMainContent){
			vRefreshMainContent=true;	
			vRefresherInfo.observers.addObserver(vdivLlistaUc);
			loadBCFromList(0, true, false);//continue refreshing, reload only Main Content
			InterfaceAgent.glowLiveBar(false,'');//stop 
		
		}
	}
	catch(error){trace(error);}
}

// #####################################################################
// Parent Classes

//Class Component
var Component = Class.create({
  initialize: function(uid) {
	this.id = uid;
	this.data = new Hash();
	this.observers = null;
	//each component must create his own presentation...
	//this.presentation= new ComponentPresentation(uid);
  },
  update: function(data) {
	//each component will do this...
  }
});

//Class ComponentPresentation
var ComponentPresentation = Class.create({
  initialize: function(uid) {
	this.id = uid;
	this.data = null;
	try{this.html = $(uid);}
	catch(error){}
  },
  pinta: function(data) {
	//each component will do this...
  }
});

var Refresher = Class.create(Component, {
	initialize: function(uid) {
		this.id = uid;
		this.observers = null;
		//this.html = $(uid); //Refresher doesn't have html
	  }
});

// ######################################################################
// Util functions

/**
 * isArray
 * tests if the Object's type is Array
 * @param testObject: object for testing
 */
function isArray(testObject) {
	return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

// ########################################################################################################
//Helper functions for ObjTree

/**
 * filterByAttribute
 * Returns an Array with the p_xmlObjTree filtered by @nomAtt == valorAtt
 * @param p_xmlObjTree: ObjTree d'entrada
 * @param nomAtt: nom de l'atribut pel qual es filtra
 * @param valorAtt: valor de l'atribut amb el qual es filtra
 */
function filterByAttribute(p_xmlObjTree, nomAtt, valorAtt){
	var vResult = new Array();

	if (isArray(p_xmlObjTree)){
		for (var i=0; i<p_xmlObjTree.length; i++){
			if (p_xmlObjTree[i]["@"+nomAtt]==valorAtt){
				vResult.push(p_xmlObjTree[i]);
			}
		}
	}
	else{
		if (p_xmlObjTree["@"+nomAtt]==valorAtt){
			vResult.push(p_xmlObjTree);
		}
	}

	return vResult;
}

/**
 * filterByNode
 * Returns an Array with the p_xmlObjTree filtered by /nomNode == valorNode
 * @param p_xmlObjTree: ObjTree d'entrada
 * @param nomNode: nom del node pel qual es filtra
 * @param valorNode: valor del node amb el qual es filtra
 */
function filterByNode(p_xmlObjTree, nomNode, valorNode){
	var vResult = new Array();

	if (isArray(p_xmlObjTree)){
		for (var i=0; i<p_xmlObjTree.length; i++){
			if (p_xmlObjTree[i].nomNode==valorNode){
				vResult.push(p_xmlObjTree[i]);
			}
		}
	}
	else{
		if (p_xmlObjTree.nomNode==valorNode){
			vResult.push(p_xmlObjTree);
		}
	}

	return vResult;
}
// ########################################################################################################

//getURLParams. Usage:
//var vParams = getURLParams(window.location.href,true);
function getURLParams(strURL,bDecode){
  var vReturn = new Array();
  if ( strURL.indexOf("?") > -1 ){
	var strQueryString = strURL.split("?")[1].split("&");
	for ( var iParam = 0; iParam < strQueryString.length; iParam++ ){
		var aux = strQueryString[iParam].split("=");
		vReturn[aux[0]]= (bDecode)? unescape(aux[1]) : aux[1];
	}
  }
  return vReturn;
}


// ##############################################################################
// AJAX - SU
/**
 * doAjaxLoginXml
 */
function doAjaxLogin(){

	if (vLoged == false){//Only login if we're not loged
		InterfaceAgent.showLoginLoading();
		//trace('trying to login...');
		var v_xmlObjTree = new XML.ObjTree();
		var v_params = {
			method:       "post" ,
			parameters:   "hiTarget=*.swf&hiErrTarget=*.swf&hiPortal=cr&hiRetrieval=S&hiRegServiceId=CR_REG&hiServiceId=CR_REG&hiUsrField=CR_NICK&hiPwdField=PWD&hiPersist=true&hiAction=11&hiRetrievalXsl=queryNom.xsl&CR_NICK="+$('idFormLogin').U.value+"&PWD="+$('idFormLogin').P.value
		};

		var v_xmlObjLogin= v_xmlObjTree.parseHTTP( v_urlSU, v_params ); //sync
		testUpdateLogin(v_xmlObjLogin, "si");
	}
}


function testUpdateLogin(p_xmlObj, userDoIt){

	var v_loggedIn;
	try{
		v_loggedIn= p_xmlObj.doc["@code"];
	}
	catch(error){
		v_loggedIn= 'err.code.undefined';
	}

	if (v_loggedIn == '0'){
		//trace('Logged in OK :)');
		vLoged=true;
		vRefresherLogin.observers.notify(p_xmlObj);
		//updateVistaLogin();
	}
	else{
		//trace('Error while trying to login :(');
		vRefresherLogin.observers.notify(p_xmlObj);
		if (userDoIt=="si"){
			InterfaceAgent.showWindowLoginFail('loginFieldUsername','LoginFailureMessage');
		}
		vLoged=false;
	}
}

function doAjaxCheckLogin(){
	var v_xmlObjTree = new XML.ObjTree();
	var v_params = {
		method:       "post" ,
		parameters:   "hiTarget=*.swf&hiErrTarget=*.swf&hiPortal=cr&hiRetrieval=S&hiRegServiceId=CR_REG&hiServiceId=CR_REG&hiAction=33&hiRetrievalXsl=queryNom.xsl"
	};

//	v_xmlObj= v_xmlObjTree.parseHTTP( v_urlSU, v_params, testCheckLogin ); //async
	var v_xmlObj= v_xmlObjTree.parseHTTP( v_urlSU, v_params, testUpdateLogin ); //async

}

// ######################

function doAjaxExitLogin(){

	var v_xmlObjTree = new XML.ObjTree();

	var v_params = {
		method:       "post" ,
		parameters:   "hiTarget=*.swf&hiErrTarget=*.swf&hiPortal=cr&hiRetrieval=S&hiRegServiceId=CR_REG&hiServiceId=CR_REG&hiAction=0&hiRetrievalXsl=login.xsl"
	};

	var v_xmlObj= v_xmlObjTree.parseHTTP( v_urlSU, v_params, pintaExitLogin ); //async
}

function pintaExitLogin	(p_xmlObj){

	var v_loggedIn;
	try{
		v_loggedIn= p_xmlObj.doc.code;
	}
	catch(error){
		trace('error exit login');
		v_loggedIn= 'err.code.undefined';
	}

	if (v_loggedIn == '0'){
		trace('Logged out OK :)');
		vLoged=false;
		vRefresherLogin.observers.notify(p_xmlObj);
		//updateVistaLogin();
	}
	else{
		trace('Error while trying to logout :(');
	}
}

function updatePubli(seccio){
	trace('updatePubli');
	$('iframePubli').src = 'ads.htm?ad='+seccio;
}

// ########################################################################################################
/////////////// FUNCT. SOLO TESTEO PARA EL LOGGER
var visible = true;
function swapLogger() {
if(visible){
document.getElementById('div_trace').className = 'div_trace_container_hidden';
document.getElementById('loggerText').innerHTML = 'mostra';
}else{
document.getElementById('div_trace').className = '';
document.getElementById('loggerText').innerHTML = 'amaga';
}
visible = !visible;
}

function emptyLogger() {
	document.getElementById('div_trace').innerHTML = "";
	}


function insertLogger(){
	var vStyle= vTraceOn? '': 'style="display:none"';
	document.write('<div class="div_trace_container" '+vStyle+'><a href="javascript:swapLogger();"><span id="loggerText">amaga</span> </a> | <a href="javascript:emptyLogger();"> esborra</a><span class="div_trace_container_empty"><input name="empty" type="checkbox" value="" checked="checked" id="div_trace_buffer_limit_check" />Buida a la linea # <input type="text" value="" id="div_trace_buffer_limit"></span><div id="div_trace"></div></div>');
}

var traceLine = 0;
var emptyBufferLimit;

function trace(msg){
	if(vTraceOn){
		traceLine++;
		if(document.getElementById('div_trace_buffer_limit_check').checked != ""){
			if(emptyBufferLimit == "" || emptyBufferLimit == undefined){ document.getElementById('div_trace_buffer_limit').value = emptyBufferLimit = 100;}
			emptyBufferLimit = Number(document.getElementById('div_trace_buffer_limit').value);
			if(traceLine >= emptyBufferLimit){ emptyLogger(); traceLine = 1;}
		}
		$('div_trace').innerHTML += '<span style=\"color:#ffcc00;\">'+traceLine+'</span> - ' +msg+'<br />'; 
	}
}

// ##############################################################################

/**
 * The Micro Recorder (flash) calls this function when loaded, to get the specific IDs
 */
function updateRecorderIDs(){
	trace ("notifiquem al flash micro: idDebat: "+idDebat+"; idPrograma:"+idPrograma);
	$('microObertFlashEngine').setDataVarsID( idDebat , idPrograma );		
}

/**
 * Live Player utils:
 */
function loadUrlStreaming(){
	var v_xmlObj;
	var v_xmlObjTree = new XML.ObjTree();
	var v_params = {
		method:       "get"
		,parameters:   'hiTarget=*.swf&hiPortal=cr&hiRegServiceId=CR_REG&hiErrTarget=*.swf&hiAction=99&hiServiceId=CR_REG&hiRetrievalXsl=player.xsl&AGENT=CR&FORMAT=FLA&QUALITY=A&IDVIDEO=352'
		
	};
	try{v_xmlObj= v_xmlObjTree.parseHTTP( v_urlSU, v_params ); }//sync
	catch(error){trace("Error trying to load streaming info xml: "+error); v_streaming="";}
		
	loadPlayerDirectes(v_xmlObj);
}

function loadPlayerDirectes(p_xmlObj){
	var v_streaming;
	try{ v_streaming= p_xmlObj.bbd.item.data;}
	catch(error){trace("Error trying to load streaming info data: "+error); v_streaming="";}
	//cp44417.live.edgefcs.net/live|@|CatClassica_FLV_1@1246
	trace("Stream: "+v_streaming);
	insertSimpleFlash('flash/player_directe_cnm.swf?streamUrl='+v_streaming,213,35);
}

function getDataTimestamp() {
	return v_dataTimestamp;
}

function getTimestamp() {
	return v_timestamp;
}

function incTimestamp() {
	v_timestamp++;
}