
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);
}

var _sendMsgDiv;

function invia_mess_click(where)
{
	
	if ( _sendMsgDiv!=undefined)return;
	
	 var elX,elY;
	 if (where == undefined)
	 {
	 	 elX=100;
	 	 elY=100;
	 }
	 else
	 {
	   elX = getX(where)-260;
	   elY = getY(where)-10;	
	 }
	 		
	 var div = document.createElement('div');
	 div.style.width='280px';
	 div.style.backgroundImage='url(http://www.iverba.com/img/scor1.png?v2)';
	 
	 div.style.height='152px';
	 div.style.display='block';
	 div.style.position='absolute';

	 div.style.top=elY.toString()+'px';
	 
	 div.className='ttMsgSend';
	 div.style.left=elX.toString()+'px';
	 
	 document.documentElement.appendChild(div);
	 
	 var docCode ='';
	 
	 if (username == 'Ospite')
	 {
	 	
	   location.href='http://www.vitecontrapposte.com/login.forum?connexion';
	   return;	
	 }
	 
	 if (username == 'Ospite')
	   	 docCode = 'Nick: <input type="text" size="10" value="Ospite" id="ttNick" />';
	 else
	 	   docCode = 'Nick: <strong>'+username+'</strong>';
	 	   
	 	   docCode += ' (<a href="#" onclick="chiudi_msg_invia();return false">Annulla</a>) ';
	 	   
    docCode = '<div style="padding-bottom:5px;font-size:13px;">'+docCode+'</div>';
   docCode+='Messaggio:<br /><input type="text" size="28" id="ttMsg" /><br /><br /><input type="button" id="btnTT" value="Invia" onclick="invia_il_msg_dd();" />';		 		
	 div.innerHTML = docCode;
	 _sendMsgDiv=div;
}

var _sentMsg, _sentNick;
function chiudi_msg_invia() { 	document.documentElement.removeChild(_sendMsgDiv);_sendMsgDiv=undefined; }
function invia_il_msg_dd()
{
	 
	 var nick = username;
	 
	 if (nick == 'Ospite')  nick = document.getElementById('ttNick').value+' (ospite)';
	 var msg = document.getElementById('ttMsg').value;
   
   _sendMsgDiv.innerHTML = '<div class="sendMsgLoad"><img src="http://www.more.com/images/accents/loader.gif" /> Invio in corso ...</div>';
   
   _sentMsg = msg;
   _setNick = nick;
   
   var bObj = new JSONscriptRequest('http://www.iverba.com/vt.mgmt.php?op=sendmsg&nick='+escape(nick)+'&testo='+escape(msg));
   bObj.buildScriptTag(); 
   bObj.addScriptTag();
   
   
}



jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
        
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

function msg_serv_resp(id, res, res2)
{
	

	if (id == 0)
	{
	document.documentElement.removeChild(_sendMsgDiv);
	
		 _sendMsgDiv=undefined;
	   if (res == 0)
	   	  alert('Puoi inviare massimo 5 messaggi al giorno');

	   if (res == 2)
	   	  alert('Puoi inviare un messaggio di massimo 150 caratteri');

	   if (res == 3)
	   	  alert('Puoi utilizzare un nick di massimo 60 caratteri');

     if (res == 1)
     {
     	  
          alert('Messaggio inviato');
         var html = document.getElementById('ticker01');
         var oldhtml = html.innerHTML;
         html.innerHTML = unescape(res2)+oldhtml;

	   }
   }
	
}
function getY( oElement  )
{
    var iReturnValue = 0;    
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
}
return iReturnValue;
}


function getX( oElement )
{
    var iReturnValue = 0;
    
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
