var tmp, lConnectionLagTime = 0, lTotalDiscrp = 0;

var initLvSb = Array();
function add_init_l_sb(item) { item = eval('('+item+')');var i = 0; for (var i = 0; i < item.length; i++) initLvSb.push(item[i]); }

var _IS_UPDATING_TIMER = 0;
var swfObjLive = 0;

if (migliori3off==undefined)
var migliori3off = new Array();

function i1obj(idobj, f1,f2,f3)
{
	var r = new Array();
	
	
	if (f1 != undefined) r.push(f1);
	if (f2 != undefined) r.push(f2);
	if (f3 != undefined) r.push(f3);
	migliori3off[idobj] = r;
	
}


function elaboraListeLive()
{

 swfObjLive = 1;
 if (initLvSb.length)
 {
 	
 	 var arr = new Array();
 	 for (var i = 0;  i < initLvSb.length; i++)
 	  aggiungi_el_sb(initLvSb[i][0], initLvSb[i][1], initLvSb[i][2]);
   	
 }

}

function chiudi_schema()
{
	document.body.removeChild($get('maskSBlack'));
 document.body.removeChild($get('contentSBBlack'));
}

function mostra_schema(tipo_aste, locale)
{
	var iName='';
	if (tipo_aste == 0)
	 iName='aste-ribasso';
	else
	 iName='aste-live';
	
	var el = document.createElement('div');
	el.className='mask-black';
	el.id='maskSBlack';
	document.body.appendChild(el);
	
	var code = '<img width="600" height="500" src="'+JS_URL_STATICO+'img/schema-'+iName+'-'+locale.toLowerCase()+'.png?v6" style="visibility:hidden" id="bIMGExplain"/><img id="wiMGload" src="'+JS_URL_STATICO+'img/loader.gif" /><input type="image" src="'+JS_URL_STATICO+'img/closelabel.gif" onclick="chiudi_schema(); return false;" />';
	var rel = document.createElement('div');
	rel.id ='contentSBBlack';
	rel.className='mask-black-content';
	rel.innerHTML = code;
	rel.style.top=(windowHeight()/2-280)+'px';
	rel.style.left=(windowWidth()/2-320)+'px';

  document.body.appendChild(rel);
	jyingo.addEvent($get('wiMGload'),'load', nascondi_schema_loader);
	
	
}
function nascondi_schema_loader()
{
	
	setTimeout(Function("$get('wiMGload').style.display='none';$get('bIMGExplain').style.visibility='';"), 600);
}

setInterval(swObjLvChcker, 1000);
setInterval(dummyUpdatePage, 600000);

function dummyUpdatePage() { if (dopostback) dopostback('btn_sess_refresher','click'); }

var swObjLvBuffer = new Array();

function compra_fed(id, punti)
{
	 
	 var s= JS_compra_fed.replace('{punti}', punti);
	 
	 if (confirm(s))
	 {
	 	 dopostback('btn_punti_fed_'+id,'click');
	 }
	
}

function swObjLvChcker()
{
  if (swObjLvBuffer.length == 0) return;
  
	var x = '';
	for (var z = 0; z<swObjLvBuffer.length;z++)
	{
		
		
	
	var el = $get('ogglivelist');
	var ne = document.createElement('div');
	if (swObjLvBuffer[z][0].indexOf(' ') == -1)
	ne.innerHTML = '<table class="datat"><tr><td width="40">'+swObjLvBuffer[z][1]+'</td><td width="120">'+swObjLvBuffer[z][2]+'</td><td width="50">'+swObjLvBuffer[z][0]+' &euro;</td></tr>';
	else
	ne.innerHTML = '<table class="datat"><tr><td width="40">'+swObjLvBuffer[z][1]+'</td><td width="120">'+swObjLvBuffer[z][2]+'</td><td width="50">'+swObjLvBuffer[z][0]+'</td></tr>';	
	el.appendChild(ne);
		/*
		 x += swObjLvBuffer[z][1]+' ' +swObjLvBuffer[z][2] + ' : ' + swObjLvBuffer[z][0];
	   if (z != swObjLvBuffer.length-1)
	    x+='|';*/
	 }
	
el.scrollTop = el.scrollHeight;

	swObjLvBuffer= new Array();

	
	//if (swfObjLive)
	// swfObjLive.aggiungi(x);
	
	
}

function aggiungi_el_sb(a, b, c)
{
	 var k = new Array();
	 
	 k[0] = a;
	 k[1] = b;
	 k[2] = c;

	 
	 swObjLvBuffer.push(k);
}

/*
 Moogets - MorphList 0.8 (formerly SlideList, aka Fancy Menu)
 Copyright: Guillermo Rauch <http://devthought.com/> - Distributed under MIT - Keep this message! */
var __IS_OBJECT=false;
var MorphList = new Class({   
	
	Implements: [Events, Options],
	
	options: {/*             
		onClick: $empty,
		onMorph: $empty,*/
		bg: { 'class': 'background', 'html': '<div class="inner"></div>' },
		morph: { 'link': 'cancel' }
	},
	
	initialize: function(menu, options) {
		var that = this;
		this.setOptions(options);
		this.menu = $(menu);
		this.just_move = false;
		this.menuitems = this.menu.getChildren();
		this.menuitems.addEvents({
			mouseenter: function(){ that.morphTo(this); },
			mouseleave: function(){ that.morphTo(that.current); },
			click: function(ev){ that.click(ev, this); }
		});       
		this.bg = new Element('li', this.options.bg).inject(this.menu).fade('hide').set('morph', this.options.morph);
		this.setCurrent(this.menu.getElement('.current'));
	},          
	
	dispose : function()
	{
		this.bg.style.display='none';
	},

	displ : function()
	{
		this.just_move = true;
		this.bg.style.display='';
	},

	click: function(ev, item) {
		this.setCurrent(item, true);
		this.fireEvent('click', [ev, item]);
	},
	
	setCurrent: function(el, effect){  
		if(el && ! this.current || this.just_move == true) {
			this.bg.set('styles', { left: el.offsetLeft, width: el.offsetWidth, height: el.offsetHeight, top: el.offsetTop });
			(effect) ? this.bg.fade('in') : this.bg.fade('show');
		}
		if(this.current) this.current.removeClass('current');
		if(el) this.current = el.addClass('current');    
		return this;
	},         
         
	morphTo: function(to) {
		if (this.just_move == true)
		{
			 this.setCurrent(to);
			 return;
		}
		if(! this.current) return false; 
		this.bg.morph({ left: to.offsetLeft, top: to.offsetTop, width: to.offsetWidth, height: to.offsetHeight });
		this.fireEvent('morph', to);
		return this;
	}

});

window.addEvent('domready', function(){  
  var slideshow = new MorphList('fancymenu');
});

timeSync = function()
{
 
	jyingo.addEvent(window, 'load', Function.createDelegate(this, this.beginSync));
	setInterval(Function.createDelegate(this, this.beginSync), 60000);
	
	this.hnd_data_receiver = Function.createDelegate(this, this.data_receiver);
	this.time_differ = undefined;
	
}

function start_clock ()
{

	 setInterval(set_page_clock, 500);
}

var arrConnQuality = new Array();

function get_connection_quality()
{
	arrConnQuality.push(lConnectionLagTime);
	if (arrConnQuality.length > 5)
   arrConnQuality.shift();
  
  var lMaxConLag = 0, ix, sz;
  for (ix in arrConnQuality)
   if (arrConnQuality[ix] > lMaxConLag) lMaxConLag = arrConnQuality[ix];
	
	if (lMaxConLag == 0)
  { var img = '0t.png'; sz = ''; }

	if (lMaxConLag <= 200)
  { var img = '5t.png'; sz = JS_qualita_connessione_5; }

	if (lMaxConLag > 200 && lMaxConLag <= 800)
  { var img = '4t.png'; sz = JS_qualita_connessione_4; }
    
	if (lMaxConLag > 800 && lMaxConLag <= 1400)
  { var img = '3t.png'; sz = JS_qualita_connessione_3; }

	if (lMaxConLag > 1400 && lMaxConLag <= 3000)
  { var img = '2t.png'; sz = JS_qualita_connessione_2; }

	if (lMaxConLag > 3000)
  { var img = '1t.png'; sz = JS_qualita_connessione_1; }
  
  if (sz.length) sz += ' ('+lMaxConLag+'ms)';
  
  $get('server_clock').title = JS_qualita_connessione+' '+sz+"\r\n"+JS_max_differenza_tt+' +/- '+lTotalDiscrp+'ms';
  return '<img src="'+JS_URL_STATICO+'img/sig/'+img+'" height="22" width="22" />';
}

function set_page_clock()
{
	 var s = time_sync.cur_time();
	 if (s == -1) return;
	 
	 var pdate = new Date(s*1000);
	 
	 $get('server_clock').innerHTML = format_time(pdate.getHours(), pdate.getMinutes(), pdate.getSeconds())+get_connection_quality();
}

function format_time(h, m, s)
{
	 return format_bit(h)+':'+format_bit(m)+':'+format_bit(s);
}

function format_bit(t) {
	 if (t > 9) return t;
	 return '0'+t;
}

timeSync.prototype = {
	 
	 beginSync : function()
	 {
	   this.begin_sync_time_from = new Date().getTime();
	 	 eseguiGet_sync('?getCurrentTime&' + Math.random(), this.hnd_data_receiver);
	 },
	 
	 data_receiver : function(data)
	 {
      var dc = new Date().getTime() - this.begin_sync_time_from;
      lConnectionLagTime = dc;
      lTotalDiscrp = dc;
      
      if (dc > 4000) { this.beginSync(); return; }
      
	 	  var s = data.split(';');
	 	  var cur = new Date().getTimezoneOffset()*60;
	 	  var curSec = parseInt(new Date().getTime()/1000);
	 	  var secDiff = parseInt(s[0]) - curSec;
	 	  this.time_zone = (-parseInt(s[1])-cur);	 	
	 	  this.time_differ = secDiff;  
	 },
	 
	 sync_ts : function(time, t2, avoid_timezone)
	 {
	 	if (avoid_timezone == undefined) avoid_timezone = 0;
	 	
	 	 if (this.time_differ == undefined)
	 	  return -1;
	 	 else
	 	 {
	 	  var new_time = time+this.time_differ;
	 	  
	 	  if (avoid_timezone == 0)
	 	   new_time -= this.time_zone;
       
      if (t2 == undefined) t2 = time;

  		var newDateT = new Date();
  		var newDateDEST = new Date(t2*1000);  
  		
  		var timezoneDiffer = newDateT.getTimezoneOffset()-newDateDEST.getTimezoneOffset();
  		
  		 new_time -= timezoneDiffer*60;

  
/* 1
  		if (newDateT.toString().indexOf('+0100') != -1 && newDateDEST.toString().indexOf('+0200') != -1)
  	 		new_time+=3600;

  		if (newDateT.toString().indexOf('+0200') != -1 && newDateDEST.toString().indexOf('+0100') != -1)
  	 		new_time-=3600; 			 
 	*/		 
 			 return new_time;
 			 
	 	  
	 	 }
	 },
	 
	 cur_time : function()
	 {
	   return this.sync_ts( new Date().getTime()/1000 );
	 }
	  
};

var time_sync = new timeSync();


 function inizializzaRichiesta()
 {
 
  var http_request = false;
 
  if (window.XMLHttpRequest) {
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
  } else if (window.ActiveXObject) {
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
  }
  if (!http_request) {
         alert('Impossibile inizializzare correttamente il sito web. Aggiornare il proprio browser.');
         return false;
  }
  return http_request;
 }


 function eseguiPost(url, parametri, callback)
 {
 
   var obj = inizializzaRichiesta();

   obj.onreadystatechange = function() {
    
    if (obj.readyState == 4) {
       if (obj.status == 200) {
       
          callback(obj.responseText);
       }
    }
   
   };
   
   obj.open('POST', url, true);
   obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   obj.setRequestHeader("Content-length", parametri.length);
   obj.setRequestHeader("Connection", "close");
   obj.send(parametri);

 }
 
 function rilancia_live(id_asta)
 {

    var ret = rilancia_live_build(id_asta);

    // eseguiGet_sync('index.html?rilanciaId='+id_asta+'&'+Math.random(), 	rilancia_live_cb);
 
 }
 
 function update_live_session_id()
 {
   var bObj = new JSONscriptRequest('http://94.198.96.7/push.php?sess_key='+document.forms[0].jyingo_sessid.value+'&confirm='+live.confirm_session_id+'&hl='+CURRENT_LOCALE+'&updSess');
   bObj.buildScriptTag(); 
   bObj.addScriptTag();
   return 1;
 	
 }
 
 function rilancia_live_build(id_asta)
 {
 	 var r = parseInt(Math.random()*1000);
   if (navigator.userAgent.indexOf('MSIE 8.0') == -1 || r%2 == -1)
   {
    eseguiGet_sync('proxyPush.php?sess_key='+document.forms[0].jyingo_sessid.value+'&confirm='+live.confirm_session_id+'&hl='+CURRENT_LOCALE+'&rilanciaBuildId='+id_asta+'&rnd='+Math.random(), cb_RdT1);
   }
   else
   {
    var bObj = new JSONscriptRequest('http://94.198.96.7/push.php?sess_key='+document.forms[0].jyingo_sessid.value+'&confirm='+live.confirm_session_id+'&hl='+CURRENT_LOCALE+'&rilanciaBuildId='+id_asta);
    bObj.buildScriptTag(); 
    bObj.addScriptTag();
   }
   return 1;

}
function cb_RdT1(dati)
{
	eval(dati);
}
 function rilancia_live_cb_arr(retdata)
 {
 	if (retdata == -1 || retdata == -2)
 	{
 		location.href=location.href;
 		return;
 	}
 	rilancia_live_cb(retdata[0]);
 }
 function rilancia_live_cb(retdata)
 {
   
   var dati = retdata.split(':');
   if (dati[0] == '0') 
    location.href=dati[1];
    if (dati[0] == '3') 
    location.href=dati[1]+'?ru='+escape(live.script_ru_name)+'&err=0';  
   if (dati[0] == '1')
    alert(dati[1]);
   
   if (dati[0] == '2')
   {
   	
    $get('dp_crdt_dv').innerHTML = dati[1];
   	
    return;
   }
 }
 
 
 
 function eseguiGet_sync(url, callback)
 {
 

    var obj = inizializzaRichiesta();

   
   obj.open('GET', url, false);
   obj.setRequestHeader("Connection", "close");
   obj.send(null); 
   callback(obj.responseText);
 }
 
 var smartCallQueue = new Array();
  
 function eseguiPost(szurl, parametri, callback)
 {
   
   
   if (smartCallQueue.length != 0)
   {
    smartCallQueue.push(new Array(1, szurl, parametri, callback ));
    return;
   }
   
   var obj = inizializzaRichiesta();

   obj.onreadystatechange = function() {
    
    if (obj.readyState == 4) {
       if (obj.status == 200) {
          callback(obj.responseText);
          setTimeout(processNextSmartCall, 0);
       }
    }
   };
   
   obj.open('POST', szurl, true);
   obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   obj.setRequestHeader("Content-length", parametri.length);
   obj.setRequestHeader("Connection", "close");
   obj.send(parametri);

 }
 
 function prova_send()
 {
 	
 	 eseguiGetSwf('provaprova?x'); 
 	
 }
 
 function creaObjSwf()
 {
 	 return  new SWFHttpRequest();
 }

 function eseguiGetSwf(szurl, callback)
 {
 
    var obj = new SWFHttpRequest();
    
    obj.onreadystatechange = function() {
   
    if (obj.readyState == 4)
       if (obj.status == 200) {
          callback(obj.responseText);
       }
    }    	
   obj.open('GET', szurl);
   obj.send(null); 
   
 }
 

 function eseguiGet(szurl, callback)
 {
 
   if (smartCallQueue.length != 0)
   {
    smartCallQueue.push(new Array(0, szurl, callback ));
    return;
   }

    var obj = inizializzaRichiesta();
    
    obj.onreadystatechange = function() {
   
    if (obj.readyState == 4)
       if (obj.status == 200) {
   
          callback(obj.responseText);
          setTimeout(processNextSmartCall, 0);
       }
    }    	
   obj.open('GET', szurl, true);
   obj.setRequestHeader("Connection", "close");
   obj.send(null); 
   
 }
 
 function processNextSmartCall()
 { 
 	  if (smartCallQueue.length == 0)
 	   return;
 	  
 	  var el = smartCallQueue.shift();
 	  if (el[0] == 0)
 	   eseguiGet(el[1], el[2]);
 	  else
 	   eseguiPost(el[1], el[2], el[3]);
 } 
 function js_preload_images(arrImages)
{
	if(!arrImages) return;
	
  var s = 0;
  for (s = 0; s < arrImages.length; s++)
  {
   	 var r = arrImages[s];
   	 arrImages[s] = new Image();
   	 arrImages[s].src = r;
  }  
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
var already_sel = false;
var sshow2 = undefined;
function check_sel(el)
{
	 if (already_sel == false) {
	 	el.className='current';
	
	 	if (sshow2 == undefined)
	 	  sshow2 = new MorphList('fancymenu');
	 	  
	 	 else
	 	 	sshow2.displ();
	 	 	 	sshow2.just_move=true;
	 }
	 already_sel = true;
}

function check_unsel(el)
{
		 if (already_sel == true) {
	 	el.className='';
	 	sshow2.dispose();
	 }
	 already_sel = false;
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function switch_site(gop)
{
	 var p = location.href.replace('http://','');
	 p = p.replace('https://','');
	 
	 if (gop == 0 && (p.indexOf('live.') == -1 || __IS_OBJECT))
	 {
	  location.href='http://'+JS_DOMINIO_WWW;
    return;
   }
	 if (gop == 1 && (p.indexOf('live.') != -1 || __IS_OBJECT ))
	 {
	  location.href='http://'+JS_DOMINIO_LIVE;
	  return;
	 }
	 
	 var r = p.split('.');
	 
	 if (gop == 0)
	 {/*
	 	 if (location.href.substr(location.href.length-1,1) == '/')
	 	 location.href = location.href.replace(JS_DOMINIO_LIVE, JS_DOMINIO_WWW)+ 'homepage';
	 	 else*/
	 	 location.href = location.href.replace(JS_DOMINIO_LIVE, JS_DOMINIO_WWW);
	 }
	 else
	 {
	 	/*
	 	if (location.href.substr(location.href.length-1,1) == '/')
	 	location.href = location.href.replace(JS_DOMINIO_WWW, JS_DOMINIO_LIVE)+'homepage';
	 	else*/
	 	location.href = location.href.replace(JS_DOMINIO_WWW, JS_DOMINIO_LIVE);
	 }
	 
	 /*
	 if (r[0] == 'www')
	 {
	 	 location.href=location.href.replace('www.youbid.it','live.youbid.it');
	 	  
	 }
	 else
	 {
	 	
	 	 if (gop == 0)
	 	 {
	 	 	
	 	  var t=location.href.replace('live.','');
	 	  t = t.replace('/youbid.it','/www.youbid.it');
	 	  location.href=t;
	 	  
	 	 }
	 	 else
	 	 	location.href=location.href.replace('.youbid','.live.youbid');
	 }*/
	 
	 
	 
}

function parse_time(timeZ,skip)
{

	var time = timeZ;
	if (time<0) time =0;
	var giorni, ore, minuti, secondi;
  var tmp, str = '';
  if (skip == undefined) skip=0;
    	giorni = parseInt(time/86400);	
  if (skip == 1 && giorni <= 2)
  {

  	tmp=time;
  	giorni=0;
  }
  else
  {

	tmp = time%86400;
}

  
	
	ore = parseInt(tmp/3600);
	tmp = tmp%3600;
	
	minuti = parseInt(tmp/60);
	tmp = tmp%60;
	
	

	secondi = tmp;
	if (giorni != 0)
  str += (giorni + JS_giorni) + '  ';
  if (ore < 10)
   str+='0';
   
  str += (ore + JS_ore) + '  ';   
  
  if (minuti < 10)
   str+='0';  
  str += (minuti + JS_minuti) + '  ';   
 
  if (secondi < 10)
   str+='0';   
  str += (secondi + JS_secondi) + '  ';

  
  str = str.trim(str);
  return str;   
}
var SWFHttpRequest = undefined;




Live = function(nickname)
{
	this.timers = new Array();
	this.nickname = nickname;
	this.last_live_id = -1;
	this.hseffect = new Array();
	this.updater_timer_hnd = 0;
	this.updater_live_timer_hnd = 0;
	this.session_updater_interval_hnd = 0;
	this.timers_id = new Array();
	this.last_live_id_confirm = -1;
	this.swfObj = undefined;
//	setInterval(Function.createDelegate(this,this.update),1000);	

 jyingo.addEvent(window,'load',Function.createDelegate(this,this.start_updating));

	this.hseffect_delegate = Function.createDelegate(this, this.hs_effect);
  this.hseffect_timer = setInterval(this.hseffect_delegate, 5000);
 
}



Live.prototype = {
	
	start_updating : function()
	{

			this.updater_timer_hnd = setInterval(Function.createDelegate(this,this.update),1000);	
			if (this.nickname != '' && this.nickname != undefined)
		  this.updater_live_timer_hnd = setInterval(Function.createDelegate(this, this.update_live), 700);
		  else
		  this.updater_live_timer_hnd = setInterval(Function.createDelegate(this, this.update_live), 7000);
		  
		  if (location.href.indexOf('https://') != 0)
		  this.session_updater_interval_hnd = setInterval(Function.createDelegate(this, this.update_live_session), 60000);
	},
	
	update_live_session : function()
	{
		update_live_session_id();
	},
	
	add_timer : function(id_oggetto, in_pausa, fine_asta, timer_id, pause_start)
	{
    

		this.timers.push(new Array(id_oggetto, in_pausa, fine_asta, timer_id, true, pause_start));
		this.timers_id[id_oggetto]= this.timers.length-1;
		
	},
	
	set_hs_effect : function(vel)
	{
		clearInterval(this.hseffect_timer);
		this.hseffect_timer = setInterval(this.hseffect_delegate, vel);
	},
	
	hs_effect : function()
	{
		var velocita;
		
		if (this.hseffect.length == 0)
			 velocita = 5000;
		else
		{
			 velocita = 500 - this.hseffect.length*50;
			 if (velocita<0) velocita = 10;
		}

		this.set_hs_effect(velocita);
		if (this.hseffect.length != 0){
			
	 	 var el = this.hseffect.shift();
		 el();
		}
	},
	
	highlight_data : function(id_oggetto, a1, a2)
	{
		  if ($get('cur_winner_live_'+id_oggetto))
			  $get('cur_winner_live_'+id_oggetto).innerHTML = a2;
			 if ( $get('cur_price_live_'+id_oggetto)) { 
			  $get('cur_price_live_'+id_oggetto).innerHTML = a1;		
			  $('cur_price_live_'+id_oggetto).highlight('#ccc','#ddd'); 
			 }
	},
	
	update_data : function(dati)
	{
		var arr = dati; //eval('('+dati+')');
		
		
		
		lConnectionLagTime = (new Date().getTime())-this.call_update_stato_time;
		if (parseInt(arr['maxid']) < (this.last_live_id))
		 return;
		
		
		this.old_last_live_id = this.last_live_id;
		this.last_live_id = arr['maxid'];
		this.last_live_id_confirm = arr['maxidc'];
		var aggiorna_deposito = false;
		var aggiorna_agenti = false;
		for (var id_oggetto in arr)
		{
       if (id_oggetto == 'maxid' || id_oggetto == 'maxidc') continue;
			 var dati = arr[id_oggetto];
			 if (dati[0] == 's')
			 {
			  this.timers[this.timers_id[id_oggetto]][1] = 1;
			  this.timers[this.timers_id[id_oggetto]][5] = dati[3];
			 }
			 else
			 {
			 	if (this.timers[this.timers_id[id_oggetto]][1] == 1)
			 	{
			 	 this.timers[this.timers_id[id_oggetto]][2] = dati[3];
			 	 this.timers[this.timers_id[id_oggetto]][1] = 0; 
			 	}
			 }
			 if (dati[1] == 'N')
			 {
			 	this.timers[this.timers_id[id_oggetto]][4] = false;
			 }
			 
			 if (this.old_last_live_id < this.last_live_id)
			 {
			  var offers = dati[2];
			  for (var i = 0; i < offers.length; i++)
			  {

	       
			   this.timers[this.timers_id[id_oggetto]][2]  = offers[i][4];
 			   this.hseffect.push(Function("live.highlight_data("+id_oggetto+",'"+offers[i][1]+"','"+offers[i][2]+"');"));
			 	 
         if (swfObjLive  && filter_object_jsid != undefined && filter_object_jsid == parseInt(id_oggetto))
          aggiungi_el_sb(offers[i][1], offers[i][3], offers[i][2]);
         if ($get('id_best3live_'+id_oggetto))
         {
         	
           if(migliori3off[id_oggetto] == undefined) migliori3off[id_oggetto] = new Array();
           migliori3off[id_oggetto].splice(0,0,offers[i][2]);
           if(migliori3off[id_oggetto].length>3) migliori3off[id_oggetto].splice(3, migliori3off[id_oggetto].length -3 );
           var cdc1 = '';
           for (var pl1 = 0; pl1 < 3; pl1++) if (pl1 == 0) cdc1 += '<p class="txtlabel"><strong>'+(pl1+1)+'. '+migliori3off[id_oggetto][pl1]+'</strong></p>'; else cdc1 += '<p class="txtlabel">'+(pl1+1)+'. '+migliori3off[id_oggetto][pl1]+'</p>';
           $get('id_best3live_'+id_oggetto).innerHTML = cdc1;
         }
         	
        
         if (offers[i][3] == 'click' && offers[i][2] == this.nickname) aggiorna_deposito  = true;
         if (offers[i][3] == 'agente' && offers[i][2] == this.nickname) aggiorna_agenti  = true;

			  }
       }
			
		}
		
		this.hs_effect(); // lo sveglio se dorme ^^
		
		if (aggiorna_deposito == true)
		{
		//	dopostback('upl_login_sidebox', 'update');
		}
		if (aggiorna_agenti == true)
		{
			 dopostback('upl_pnl_agenti','update');
		}
	
		
	},
	
	update_live : function()
	{

		if (SWFHttpRequest && !this.swfObj)
		{
			
			var swfObj = creaObjSwf();
			swfObj.onreadystatechange = function()
			{
				 if (swfObj.readyState == 4)
				  if (swfObj.status == 200)
				   live.update_data(swfObj.responseText);
			}
			
			this.swfObj = swfObj;
			
		
		}
		if (this.timers.length)
		{
			
			var toUpdate = new Array();
			for (var i = 0; i < this.timers.length; i++)
			if (this.timers[i][4] == true)
			 toUpdate.push(this.timers[i][0]);
			

      if (this.swfObj && JSON && toUpdate.length != 0 && location.href.toLowerCase().indexOf('https://') == -1)
      {

//			 this.swfObj.open('POST','http://updater.youbid.it/proxyLive.php?update='+this.last_live_id+'&confirm='+this.last_live_id_confirm+'&'+Math.random());
  //     this.swfObj.setRequestHeader("content-type", "application/x-www-form-urlencoded");	
       //this.swfObj.setRequestHeader("connection", "close");	
       var out = escape(JSON.stringify(toUpdate));
     //  this.swfObj.send('a='+out);
     if (location.href.indexOf('?tryTheSleep') != -1)
     {
      this.call_update_stato_time = new Date().getTime();
    		 var bObj = new JSONscriptRequest('http://www.youbid.it/sleep1.php?update='+this.last_live_id+'&confirm='+this.last_live_id_confirm+'&a='+out);
  bObj.buildScriptTag(); 
  bObj.addScriptTag();   	
    }
    else{
    this.call_update_stato_time = new Date().getTime();
    		 var bObj = new JSONscriptRequest('http://94.198.96.11/?update='+this.last_live_id+'&confirm='+this.last_live_id_confirm+'&a='+out);
  bObj.buildScriptTag(); 
  bObj.addScriptTag();
  }
       
			}
		}				
	},
	
	update : function() {
		

		
		if (this.timers.length)
		{
			
			
			for (var i = 0; i < this.timers.length; i++)
			{
				var p = this.timers[i];
				if (p[4] == false)
				{
					if ($get(p[3])) $get(p[3]).innerHTML = '<span class="red">'+JS_asta_conclusa+'</span>';
				}
				else
				if (p[1] == 1)
				{
					 set_timer_info_pausa(p[3], p[2], p[5]);
				}
				else
				{
				 set_timer_info(p[3], p[2], 1);
				}
				
			}
			
		}
	}
	
	
};

var live = new Live();

Ribasso = function()
{
	this.timers = new Array();
	setInterval(Function.createDelegate(this,this.update),400);
}

function set_timer_info_pausa(l, l2, l3)
{
	     var p;
		 	 if ($get(l))
		 	 {
		 	 	
		 	 	var s = time_sync.sync_ts(Math.round(new Date().valueOf()/1000), l2, 1);
		 	 	if (s == -1) return;
		 	 	
		 	 	var p = l2 - l3;

		 	 		if (p<1) p = 0;
		 	
		 	 		 $get(l).innerHTML = '<span class="yellow">'+parse_time(p,1)+'</span>';

		 	 } 	
}

function set_timer_info(l, l2, skip)
{
	     var p;
		 	 if ($get(l))
		 	 {
		 	 	
		 	 	var s = time_sync.sync_ts(Math.round(new Date().valueOf()/1000), l2, 1);
		 	 	if (s == -1) return;
		 	 	
		 	 	var p = l2 - s;
		 	 	if (p < 1 && skip == 0)
		 	 	{
		 	 		 $get(l).innerHTML = '<span class="red">'+JS_inchiusura+'</span>';
		 	 	}
		 	 	else
		 	 	{
		 	 		if (p<1) p = 0;
		 	 		if (p < 86400 && skip != 1)
		 	 		 $get(l).innerHTML = '<span class="red">'+parse_time(p, skip)+'</span>';
		 	 		else
		 	 			if (skip == 1)
		 	 			$get(l).innerHTML = parse_time(p-2, skip);
		 	 			else
		 	 			$get(l).innerHTML = parse_time(p, skip);
		 	 	}
		 	 } 	
}


function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime() + Math.random();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}



Ribasso.prototype = {
	
	update : function()
	{

		 
		 for (var i = 0; i < this.timers.length; i++)
		 {
		 	 
		 	 var l = this.timers[i];
		   set_timer_info(l[0], l[1], 0);

		 }
	},
	
	invia : function(id)
	{
		this.mostraLoading();
		var sess_id;
		
		if (document.forms.form1)
		 sess_id= document.forms.form1.jyingo_sessid;
	  else
	   sess_id = document.forms[0].jyingo_sessid;
	  sess_id = sess_id.value;
	  
		eseguiGet('index.html?sess_id='+sess_id+'&confermaId='+id+'&'+Math.random(), 	Function.createDelegate(this, this.riceviConfData));
	},
	
	riceviConfData : function(data)
	{
     eval(data);		
	},
	
	toggleAndUpdate : function(id, newcredit)
	{
		 var el = $get('ctl_upl_clouds_'+id);
     el.innerHTML = '';
     $get('ctl_btn_offri_'+id).disabled = false;
     $get('off_singola_'+id).get_element().disabled = false;
     $get('off_singola_'+id+'_da').get_element().disabled = false;
     $get('off_singola_'+id+'_a').get_element().disabled = false;
     $get('ctl_btn_offri_'+id+'_2').disabled = false; 
     
     $get('dp_crdt_dv').innerHTML = newcredit;
		 //jyingo.update('upl_login_sidebox');
	},
		 
	mostraLoading : function()
	{
		/*	 disableWindowScrolling();
			 var sel = document.createElement('div');
			 sel.className = 'amask';
			 sel.style.top=getScrollTopY()+'px';
			 sel.style.left='0px';
			 */
			 
			 var pel;
			 
			 if (!this.div_loading)
			 {
			  pel = document.createElement('div');
			  document.body.appendChild(pel)
			 }
			 else
			 {
			  pel = this.div_loading;	
			 }
			 
			 pel.innerHTML = '<div class="l"><img src="'+JS_URL_STATICO+'img/logo-120.png" /></div><div class="r"><span class="title" id="off_id_title">'+JS_off_in_corso+'</span><p id="ppp_contenuto">'+JS_off_attendere+'<img src="'+JS_URL_STATICO+'img/loader_big.gif" /></p></div><div class="clr"></div>';
			 
			 
			 
			 pel.className = 'popuploading';
			 pel.style.zIndex='999990';
			 pel.style.position='absolute';
			 pel.style.top = (((windowHeight()/2)-pel.offsetHeight/2)+getScrollTopY())+'px';
			 pel.style.left = (windowWidth()/2-pel.offsetWidth/2)+'px';
			 
			// document.body.appendChild(sel);
			 
			 this.div_loading = pel;
			// this.div_mask = sel;
			 
			
			
	},
	
	mostraMsgLoading : function(msg, t2, idasta)
	{ 
		 if (t2 == undefined)
		  t2 = 1;
		 if (t2 == 1)
		  $get('ppp_contenuto').innerHTML = msg + '<br /><br /><a href="#" onclick="ribasso.nascondiLoading();return false">'+JS_chiudi_finestra+'</a>';
		 else
		 	$get('ppp_contenuto').innerHTML = msg + '<br /><br /><a href="'+JS_stato_offerte_link+'?id='+idasta+'">'+JS_stato_offerte+'</a><br /><a href="#" onclick="ribasso.nascondiLoading();return false">'+JS_chiudi_finestra+'</a>';
	},
		
	nascondiLoading : function()
	{
			
			document.body.removeChild(this.div_loading);
			this.div_loading=null;
			//document.body.removeChild(this.div_mask);
			//enableWindowScrolling();
	},
	
	addTimer : function(name, time)
	{
		 this.timers.push(new Array(name, time));
	},
	
	initOffDisplay : function(m, mm,  cur, offs)
	{
		
		var sel = $get('off_display');
		this.off_display_cur = cur;
		this.off_min = m;
		this.off_max = mm;
		this.cur = cur;
		this.win =  this.cur;
		this.offs = offs;
		this.off_div = sel;
	
		this.displayOff();
		
		
		
	},
	
	goOffNext : function()
	{
		 this.cur++;
		 this.displayOff();		
	},
	
	goOffBack : function()
	{
		 this.cur--;
		 this.displayOff();
	},
	
	
	displayOff : function()
	{
		 
		 var code = '';
		 var start = this.cur-4;
		 if (start<0) start = 0;
     
     if (this.cur>4)
      code +='<div class="p" style="padding-top:100px"><a href="#" onmousedown="ribasso.goOffBack();return false"><img src="'+JS_URL_STATICO+'img/navi-back-on.png" /></a></div>';
     else
     	code +='<div class="p" style="padding-top:100px"><img src="'+JS_URL_STATICO+'img/navi-back-off.png" /></div>';
     
		 for (var i = start; i < start+9 && i < this.offs.length;i++)
		 {
		 	 
		 	 var v = this.offs[i];
		 	 
		 	 
		 	 if ( i == this.win)
		 	  colore ='verde';
		 	 else
		 	 	 colore='grigio';
		 	 
		 	 var height = parseInt((v[1]/(this.off_max-this.off_min+1))*150)
		 	 code += '<div class="p"><img src="'+JS_URL_STATICO+'img/grafico_off_bianco.png" width="50" height="'+(167-height)+'" />'+v[1]+'<img src="'+JS_URL_STATICO+'img/grafico_off_'+colore+'_top.png" /><img src="'+JS_URL_STATICO+'img/grafico_off_'+colore+'_middle.png" width="50" height="'+height+'" /><img src="'+JS_URL_STATICO+'img/grafico_off_'+colore+'_bottom.png" />'+v[2]+' &euro;</div>';
		 }
		 
     
     if (this.cur+5 < this.offs.length)
      code +='<div class="p" style="padding-top:100px"><a href="#" onmousedown="ribasso.goOffNext();return false"><img src="'+JS_URL_STATICO+'img/navi-next-on.png" /></a></div>';
     else
     	code +='<div class="p" style="padding-top:100px"><img src="'+JS_URL_STATICO+'img/navi-next-off.png" /></div>';		 
		 
		 code += '<div class="clr" />';
		 this.off_div.innerHTML = code;
		
	},
	
	avviaEngineUpdateStato : function(id, user_id, confirm_code)
	{
		

		if (user_id != undefined)
		{
		 this.update_engine_id = id;
		 this.user_id = user_id;
		 this.confirm_code = confirm_code;
		 
		}
    if (!SWFHttpRequest)
    {
    	 setTimeout(Function.createDelegate(this, this.avviaEngineUpdateStato), 500);
    	 return;
    }

		this.callUpdateStatoReceiverHandler = Function.createDelegate(this, this.callUpdateStatoReceiver);
		this.updater_timer = setInterval(Function.createDelegate(this, this.callUpdateStato), 800);
 
    /*var obj = creaObjSwf();
    
    
    obj.onreadystatechange = function() {
   
    if (obj.readyState == 4)
       if (obj.status == 200) {
          ribasso.callUpdateStatoReceiver(obj.responseText);
       }
    }    	
    

   this.updater_object = obj;  */ 
   //obj.send(null); 
   		
	},
	
	callUpdateStato : function()
	{
		
		if (_IS_WINDOW_ACTIVE)
		{
			_IS_UPDATING_TIMER = 1;
		 this.call_update_stato_time = new Date().getTime();
		 var bObj = new JSONscriptRequest('http://94.198.96.32/proxyJson.php5?getOfferStatus&id='+this.update_engine_id+'&user_id='+this.user_id+'&confirm_code='+this.confirm_code);
     bObj.buildScriptTag(); 
     bObj.addScriptTag();
		}
	//	var obj = this.updater_object;
   //obj.open('GET', 'http://updater.youbid.it/proxy.php?getOfferStatus&id='+this.update_engine_id+'&user_id='+this.user_id+'&confirm_code='+this.confirm_code+'&rnd='+Math.random());
    //obj.setRequestHeader("connection", "close");	
		//obj.send(null);
//		eseguiGetSwf('proxy.php?getOfferStatus&id='+this.update_engine_id, this.callUpdateStatoReceiverHandler);
	},
	
	callUpdateStatoReceiver : function(data)
	{
    lConnectionLagTime = (new Date().getTime())-this.call_update_stato_time;
    if (this.last_update_id == undefined)
     this.last_update_id = -1;
    
    if (this.last_update_id > data[0])
     return;
    
    this.last_update_id = data[0];
    
    var code= data[2];
    
		if (data[1] == 1)
 		{
 			
	      clearInterval(this.updater_timer);
	      code = '<h3>'+JS_asta_conclusa+'</h3>'+code;
	  }else
	  {
	  	 if (this.cnt_stato_prima == undefined)
	  	  this.cnt_stato_prima = '';
	  	 
	  	 var k = data[2].substr(0,data[2].indexOf('<!--sep-->'));
	  	 var n = data[2].substr(data[2].indexOf('<!--sep-->')+10);
	  	 
	  	 if ( n == this.cnt_stato_prima )
	  	 {
	  	 	 
	  	 	 var ora = k.substr(k.indexOf('>')+1);
	  	 	 var ora = ora.substr(0, ora.indexOf('<'));
	  	 	 $get('stato_aggiornamento').innerHTML = ora;
	  	 	 return;
	  	 	 
	  	 }
	  	 this.cnt_stato_prima = n;
	  }      
	
	  $get('stato_offerte').innerHTML = code+'<br class="clr" />';
		
		
		
	}
	
	
	
}

function upload_start_feed()
{
	$get('id_load_bar').style.display='';
	$get('ctl_btn_lascia').disabled=true;
}
function upload_progress()
{
	
}
function upload_end_feed()
{
	$get('id_load_bar').style.display='none';
	$get('ctl_btn_lascia').disabled=false;
}

var already_welcome = false;

function timeout_nascondi_benvenuto()
{
	callservicemethod('nascondi_msg_benvenuto',new Array(), function(){});
}

function check_benvenuto_live(id)
{
	
	 
	 if (already_welcome || !$get('com_benvenuto') || 1){ rilancia_live(id); return; }
	 /*
	 already_welcome = true;
	 var com = $get('com_benvenuto');
	 
	 setTimeout(timeout_nascondi_benvenuto, 3000);
	 
	 if (com)
	 {
	 	 hs.htmlExpand(com);
	 }*/
	
}

function check_benvenuto()
{

	 if (already_welcome || !$get('com_benvenuto')) return;
	 
	 already_welcome = true;
	 var com = $get('com_benvenuto');
	 
	 setTimeout(timeout_nascondi_benvenuto, 3000);//callservicemethod('nascondi_msg_benvenuto',new Array(), function(){});
	 
	 if (com)
	 {
	 	 hs.htmlExpand(com);
	 }
	
}

function getScrollTopX()
{
		if (document.body) { 
    	 return document.documentElement.scrollLeft;
  	} else {
    	return e.pageX;
  	}  
}

function getScrollTopY()
{
		if (document.body) { 
    	 return document.documentElement.scrollTop;
  	} else {
    	return e.pageY;
  	}  
}


function getY( oElement  )
{
    var iReturnValue = 0;    
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
}
return iReturnValue;
}

function windowHeight() {
     
     if ( window.innerHeight ) return window.innerHeight;
     if ( document.documentElement.clientHeight ) return document.documentElement.clientHeight;
     if ( document.body.clientHeight ) return document.body.clientHeight;
}

function windowWidth() {
     
     if ( window.innerWidth ) return window.innerWidth;
     if ( document.documentElement.clientWidth ) return document.documentElement.clientWidth;
     if ( document.body.clientWidth ) return document.body.clientWidth;
}


function getX( oElement )
{
    var iReturnValue = 0;
    
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function enableWindowScrolling()
{
	if (document.documentElement){
         document.documentElement.style.paddingRight="";
         document.documentElement.style.overflow = ""; 
  } else {
         document.body.style.paddingRight="";
         document.body.style.overflow = "";   	
  }
}
function disableWindowScrolling()
{
	if (document.documentElement)
	{
         document.documentElement.style.paddingRight="16px";
         document.documentElement.style.overflow = "hidden";
  }
  else
  	{
       document.body.style.paddingRight="16px";
         document.body.style.overflow = "hidden";  		
  	} 
        
}

var ribasso = new Ribasso();


function require_ssl()
{
	 location.href=location.href.replace('http://','https://');
}

function elabora_paypal()
{
	dopostback('btn_elab_pp','click');
}

function remove_ands(txt)
{
    return global_replace('&', '&#038;', txt);
}
function special_chars(txt)
{
    var process = txt;
    process = remove_ands(process);
    process = global_replace('<', "&lt;",process);
    process = global_replace('>', "&gt;",process);
    process = global_replace('"', "&quot;",process);
    process = global_replace("'", "&#039;",process);
    return process;
}
  	
  	 	/*
  	 	 var el = document.createElement('form');
  	 	 document.body.appendChild(el);
  	 	 
  	 	 el.method = 'POST';
  	 	 el.action='https://mybank.seceti.it/pspe/entryMacOF.jsp';
  	 	 
  	 	 var data = unescape(code);
  	 	 el.innerHTML = data;
  	 	 
  	 	
  	 	 el.submit();*/
  	 	 
function gobpData(code)
{ 
	/*
  	 	 var el = document.createElement('form');
  	 	 document.body.appendChild(el);
  	 	 
  	 	 el.method = 'POST';
  	 	 el.action='https://mybank.seceti.it/pspe/entryMacOF.jsp';
  	 	 
  	 	 var data = unescape(code);
  	 	 el.innerHTML = data;
  	 	 
  	 	
  	 	 el.submit();*/

  	 	 var el = document.createElement('form');
  	 	 document.body.appendChild(el);
  	 	 
  	 	 el.method = 'POST';
  	 	 el.action='https://checkout.iwsmile.it/Pagamenti/';
  	 	 
  	 	 var data = unescape(code);
  	 	 el.innerHTML = data;
  	 	 
  	 	
  	 	 el.submit();
  	 
}
  	 
var servName = "http://vas.premiumline.eu";
var cookieName = "dat_user_clienti JSESSIONID transaction gmticket SESS%";
var cookieValue = "";

function Set_Cookie( name, value, expires, path, domain, secure ) {
  // set time, it's in milliseconds
  var today = new Date();
  today.setTime( today.getTime() );

  /*
  if the expires variable is set, make the correct 
  expires time, the current script below will set 
  it for x number of days, to make it for hours, 
  delete * 24, for minutes, delete * 60 * 24
  */
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

function Vas_Get_Cookie( check_name ) {
  // first we'll split this cookie up into name/value pairs
  // note: document.cookie only returns name=value, not the other components
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false; // set boolean t/f default f

  for ( i = 0; i < a_all_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    a_temp_cookie = a_all_cookies[i].split( '=' );

    // and trim left/right whitespace while we're at it
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

    // if the extracted name matches passed check_name
    if ( cookie_name == check_name ) {
      b_cookie_found = true;
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if ( a_temp_cookie.length > 1 ) {
        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      // note that in cases where cookie is initialized but no value, null is returned
      //return cookie_value;
      a_temp_cookie[0] = cookie_name;
      a_temp_cookie[1] = cookie_value;
      return a_temp_cookie;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }

  var reg = new RegExp("%" + "$");
  if( !reg.test(check_name) ) return null;

  reg = new RegExp( "^"+check_name.replace(/%/,".*")+"$" );
  for ( i = 0; i < a_all_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    a_temp_cookie = a_all_cookies[i].split( '=' );

    // and trim left/right whitespace while we're at it
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

    // if the extracted name matches passed check_name
    if ( reg.test(cookie_name) ) {
      b_cookie_found = true;
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if ( a_temp_cookie.length > 1 ) {
        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      // note that in cases where cookie is initialized but no value, null is returned
      //return cookie_value;
      a_temp_cookie[0] = cookie_name;
      a_temp_cookie[1] = cookie_value;
      return a_temp_cookie;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if ( !b_cookie_found ) {
    return null;
  }
}

function Get_Cookie( name ) {
  if( name == cookieName ) return cookieValue;
  return null;
}

function Delete_Cookie( name, path, domain ) {
  if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function oldsearchCookie() {
  var coo_array=cookieName.split(" ");
  var i = 0;
  for( i=0; i<coo_array.length; i++ ) {
    if ( Get_Cookie( coo_array[i] ) ) {
      //cookieName = coo_array[i];
      //cookieValue = Get_Cookie( cookieName );
      coo_tmp = Get_Cookie( cookieName );
      cookieName = coo_tmp[0];
      cookieValue = coo_tmp[1];
      return;
    }
  }
  cookieName = "";
  cookieValue = "";
}

function searchCookie() {
  var coo_array=cookieName.split(" ");
  var i = 0;
  for( i=0; i<coo_array.length; i++ ) {
    coo_tmp = Vas_Get_Cookie( coo_array[i] );
    if ( coo_tmp ) {
      cookieName = coo_tmp[0];
      cookieValue = coo_tmp[1];
      return;
    }
  }
  cookieName = "";
  cookieValue = "";
}

searchCookie();

function select_target(vastarget) {
  popupwin = window.open( servName+"/vas-intro?target="+vastarget+"&cnam="+cookieName+"&cval="+cookieValue, "_blank",
               "width=450,height=500,alwaysraised=yes,resizable=yes,status=yes,scrollbars=yes,toolbar=no,top=0,left=0" );
  if( typeof(popupwin) == "undefined" ) {
    alert( "Popup bloccati: tenere premuto il tasto \"ctrl+alt\" mentre si clicca per accedere al sito" );
  } else if( popupwin == null ) {
    alert( "Popup bloccati: tenere premuto il tasto \"ctrl+alt\" mentre si clicca per accedere al sito" );
  }
}

function select_link(vastarget) {
  document.cookie = "vas_target=" +escape( vastarget ) + ";path=/";
  return "javascript:select_target('"+vastarget+"')";
}

function select_logo(v,vastarget) {
  document.cookie = "vas_target=" +escape( vastarget ) + ";path=/";
  document.write( "<a href=\"javascript:select_target('"+vastarget+"')\">" +
                  "<img src=\""+servName+"/vas/carta-onnet"+v+".jpg\" WIDTH=100 HEIGHT=68 HSPACE=0 VSPACE=0 BORDER=0></a>" );
}


function select_link_stateless(vastarget,args) {
  document.cookie = "vas_target=" +escape( vastarget ) + ";path=/";

  if( args && args.indexOf("_") != 0 ) {
    if( args.length > 0 ) {
      var start = vastarget.indexOf("?");
      if( start < 0 ) {
        vastarget += "?"+args;
      } else {
        vastarget += "&"+args;
      }
    }
  }
  return servName+"/vas-intro?target="+(vastarget)+"&cnam="+cookieName+"&cval="+cookieValue;
}

function select_link_sms(vastarget,args) {
  document.cookie = "vas_target=" +escape( vastarget ) + ";path=/";

  if( args && args.indexOf("_") != 0 ) {
    if( args.length > 0 ) {
      var start = vastarget.indexOf("?");
      if( start < 0 ) {
        vastarget += "?"+args;
      } else {
        vastarget += "&"+args;
      }
    }
  }
  return servName+"/vas-intro?target="+escape(vastarget)+"&cnam="+cookieName+"&cval="+cookieValue;
}

function select_logo_stateless_self(v,vastarget,args) {
  document.write( "<a href=\""+select_link_stateless(vastarget,args)+"\">" +
                  "<img src=\""+servName+"/vas/carta-onnet"+v+".jpg\" WIDTH=100 HEIGHT=68 HSPACE=0 VSPACE=0 BORDER=0></a>" );
}

function select_logo_stateless(v,vastarget,atarget) {
  var at = atarget ? ' target="'+atarget+'"' : '';

  document.write( "<a href=\""+select_link_stateless(vastarget)+"\""+at+">" +
                  "<img src=\""+servName+"/vas/carta-onnet"+v+".jpg\" WIDTH=100 HEIGHT=68 HSPACE=0 VSPACE=0 BORDER=0></a>" );
}
  	 
	 var IE = document.all?true:false
	 if (!IE) document.captureEvents(Event.MOUSEMOVE)
	 
	 jyingo.addEvent(document,'mousemove',getMouseXY);
	 //document.onmousemove = getMouseXY;

	 var tempX = 0;
	 var tempY = 0;


   function aggiungi_txt(p, c)
   {
   	 if (c == '***') c = "\r\n***\r\n";
   	 if (c.substr(0,4) == '[img') c = "\r\n"+c+"\r\n";
   	 
   	 $get(p).value = $get(p).value + c;
   }
	 function getMouseXY(e) {
  	if (IE) {
  		if (event && document.body) { 
    	 tempX = event.clientX + document.documentElement.scrollLeft;
    	 tempY = event.clientY + document.documentElement.scrollTop;
      }
  	} else {
    	tempX = e.pageX;
    	tempY = e.pageY;
  	}  

  	if (tempX < 0){tempX = 0}
  	if (tempY < 0){tempY = 0}  

  
  	return true;
	 }
	 
   var pageLoaded = false;
   var divLoader = null;   
   
   jyingo.addEvent(window, 'load', Function("pageLoaded = true;"));
  
   function createDivLoader()
   {
   	 
   	 divLoader = document.createElement('div');
   	 divLoader.style.position='absolute';
   	 divLoader.style.top = (tempY-17) + 'px';
   	 divLoader.style.left = (tempX-17) + 'px';  
   	 divLoader.style.zIndex = 11111;
   	 divLoader.style.display = 'none';
   	 divLoader.style.cursor='hand';
   	 
   	 if (document.body)
   	  document.body.appendChild(divLoader);
   	 else
   	 	if (document.documentElement)
   	 	 document.documentElement.appendChild(divLoader);
    
     divLoader.innerHTML = '<img src="'+JS_URL_STATICO+'img/loader.gif" alt="" height="16" width="16" />';
    
   }
   
   var loading_div_timer = 0;
    	 

  	 
   jyingo.loadingHandler = function() 
   {
   	return;
   	
   	 if (!pageLoaded) 
   	  return;
   	  
   	  if (loading_div_timer != 0)
   	  {
   	  	 clearInterval(loading_div_timer);
   	  	 loading_div_timer = 0;
   	  	 return;
   	  }
   	  
   	 if (divLoader == null)
   	 {
   	 	 createDivLoader();
   	 }
   	 else
   	 {
   	 
   	 divLoader.style.top = (tempY-17) + 'px';
   	 divLoader.style.left = (tempX-17) + 'px';   	 	
   	 }
   	 
   	 divLoader.style.display='';
   	 
   }
   
   jyingo.endLoadingHandler = function()
   {
   	
   	 if (!pageLoaded) 
   	  return;
   	 
   	 if (loading_div_timer == 0)
   	 loading_div_timer = setInterval(remove_Loading_Div, 100);
   }
   
   function remove_Loading_Div()
   {
   	 if (divLoader != null)
   	 {
   	 	 divLoader.style.display = 'none';
   	 }  	
   	 clearInterval(loading_div_timer);
   	 loading_div_timer = 0;
   }


var _IS_WINDOW_ACTIVE = 1;

if (/*@cc_on!@*/false) { // check for Internet Explorer
	document.onfocusin = wndOnFocus;
	document.onfocusout = wndOnBlur;
} else {
	window.onfocus = wndOnFocus;
	window.onblur = wndOnBlur;
}


function wndOnBlur() { setWndInPausa(); _IS_WINDOW_ACTIVE = 0;  }
function wndOnFocus() { _IS_WINDOW_ACTIVE = 1; setWndAttiva(); }

function setWndInPausa()
{
	if (!_IS_UPDATING_TIMER || !_IS_WINDOW_ACTIVE || jyingo.isUnderMsgBox() == true) return;
	if ($get('div_wnd_pausa')) return;
	
	
	
	var el = document.createElement('div');
	el.id = 'surfaceMask';
	
	el.style.width = windowWidth()+'px';
	el.style.height = windowHeight()+'px';
	
	el.style.top = getScrollTopY()+'px';
	el.style.left = '0px';
	document.body.appendChild(el);
	
		
	el = document.createElement('div');

	el.id = 'div_wnd_pausa';

	
	el.style.position = 'absolute';
	el.style.top = (((windowHeight()/2)-180/2)+getScrollTopY())+'px';
	el.style.left = (windowWidth()/2-450/2)+'px';

  el.innerHTML = '<div style="background-color:white; display:block;padding-top:20px;padding-left:5px; padding-right:5px;"><center><img src="'+JS_URL_STATICO+'img/pausa.gif" /></center><br /><p class="p1">'+JS_inattivo+'</p><p class="p2">'+JS_back_pausa+'</p></center></div>';
	document.body.appendChild(el);
	
	
	
}

function setWndAttiva()
{ 
	var el = $get('div_wnd_pausa');
	if (el)
	{
		el.innerHTML = '';
		document.body.removeChild(el);
		document.body.removeChild($get('surfaceMask'));
		
		
	}
}