/*
*Create by OO 29/10/2008
*/
/**
 * MRMWI namespace and MRMWI/init namespace
 */
var MRMWI = window.MRMWI || {};
MRMWI.init = MRMWI.init || {};

/**
 * MRMWI msn channel namespace
 */
MRMWI.channel = MRMWI.channel || {};


MRMWI.channel.init = function() {
	if(navigator.appName.indexOf("Microsoft") != -1)
	{
		flash = window.flashObject;
	}
	else
	{
		flash = window.document.flashObject;
	}
	//alert("init:"+flash);
	//chiamate di test
	//flash.Flash_OnRemoteAppLoaded();
	//flash.Flash_setKeyPressed("d");
	//window.external.Channel.Initialize();
};

MRMWI.channel.Flash_OnLoad = function ()
{
	
	//da decommentare per far partire la connessione remota  Tell Windows Live Messenger we are ready to accept events.
	window.external.Channel.Initialize();
	
	
};


MRMWI.channel.test = function(){
	//flash.Flash_setKeyPressedLeft = function ();
};
MRMWI.channel.Channel_SendTo = function(data){
	//alert("Channel_SendTo send this:"+data);
	window.external.Channel.SendData(data);
};



















/**
 * MRMWI utilities namespace
 */
MRMWI.util = MRMWI.util || {};

MRMWI.util.newBrowserWin = function(){
    var elements = YAHOO.util.Dom.getElementsByClassName('external', 'a');
    for (var i=0;i<elements.length;i++){
    if (elements[i].href){
        //elements[i].title+=' (opens in new window)';
        elements[i].onclick=function(){
        	newWin=window.open(this.href,'ExternalLink');
        	//if(window.focus){newWin.focus()}
        	return false;
        	}
    }
  }
};
//YAHOO.util.Event.addListener(window, "load", MRMWI.util.newBrowserWin); 

/**
 * MRMWI Cookie Handler
 */
MRMWI.util.Cookie = {
//	myData = MRMWI.util.Cookie.Load("leNomDuCookie")  // Return the data from the cookie
	Load: function (id) {
		var search = id + "=";  
		var cookie = null;
		if (document.cookie.length > 0) { 					// if there are any cookies      
			offset = document.cookie.indexOf(search);       
			if (offset != -1) { 							// if cookie exists          
				offset += search.length; 					// set index of beginning of value         
				end = document.cookie.indexOf(";", offset);	// set index of end of cookie value         
				if (end == -1) end = document.cookie.length;
				cookie = unescape(document.cookie.substring(offset, end));   
				}    
			}	
		return cookie;	
	},

	// MRMWI.util.Cookie.Save("leNomDuCookie","VALUE",true = 1 year || false = Session only );
	Save: function (id, data, session) {
		if(!session) {
			var now = new Date();
			var expires = now.getTime() + 365 * 24 * 60 * 60 * 1000;
			var expires = new Date(expires);
			session = "; expires=" + expires.toGMTString();
		} else {
			session = "";
		}
		document.cookie = id + "=" + escape(data) + session + "; path=/";
	}		
		
};

/**
 * MRMWI Cookie QueryString
 */
MRMWI.util.GetRequestParameter = function(param) {
	var q = document.location.search || document.location.hash;
	if (param == null) { return q; }
	if(q) {
		var pairs = q.substring(1).split("&");
		for (var i=0; i < pairs.length; i++) {
			if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
				return pairs[i].substring((pairs[i].indexOf("=")+1));
			}
		}
	}
	return "";
};

/**
 * MRMWI Browser Detection (by NAME)
 */
MRMWI.util.BrowserDetection = function() {
	_ua = navigator.userAgent.toLowerCase();
    if ( _ua.indexOf( 'opera' ) != -1 ) {
		// Opera (check first in case of spoof)
		return 'opera';
	} else if ( _ua.indexOf( 'msie' ) != -1 ) {
		// Microsoft Internet Explorer and derivatives...
		return 'msie';
	} else if ( _ua.indexOf( 'safari' ) != -1 ) {
		// Safari (check before Gecko because it includes 'like Gecko')
		return 'safari';
	} else if ( _ua.indexOf( 'gecko' ) != -1 ) {
		// Gecko
		return 'gecko';
	}	
};