
function getFlashMovieObject( movieName){
  if ( window.document[movieName]){
      return window.document[movieName];
  }
  if ( navigator.appName.indexOf( "Microsoft Internet")==-1){
  	if ( document.embeds && document.embeds[ movieName]){
    	return document.embeds[ movieName]; 
    }
  } else {
   	return document.getElementById( movieName);
  }
}

function newwindow(url) {
  window.open(url,"_blank");
}  

//window.onload= function(){setTimeout(popup, 2000, "http://www.yahoo.com")};
function popup(url, fullWin){
  doPopup(url, fullWin, false)
}

function loginPopup(url, fullWin) {
  doPopup(url, fullWin, true)
}

function getDocumentHash() {
        return document.location.hash;
}

function doPopup(url, fullWin, isLogin) {
  url = unescape(url);
  //alert("url: " + url);
  
  setTimeout( function() {
    var w;
    if(fullWin){
    	w = window.open(url, "_blank");
    }
    else{
	  	w = window.open(url, "_blank", "location=1,scrollbars=1,status=1,width=750,height=600");
	}

    if(!w){
    	var flash =  getFlashMovieObject(myName);
   		if(isLogin){
   			flash.onLoginPopupBlocked();
   	 	}
   	 	else{
   	 		flash.onPopupBlocked(url);
   	 	}
    }
    
 }, 0);
 
}

function getBrowserUserAgent(){
	return window.navigator.userAgent
}

function getBrowser()
{
	var data = [
		{string: navigator.userAgent, subString: "MSIE",    identity: "IE", versionSearch: "MSIE"},
		{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
		{string: navigator.vendor,	  subString: "Apple",	identity: "Safari"},
		{prop: window.opera,                                identity: "Opera"},
	];
	for (var i=0;i<data.length;i++)
	{
		var string = data[i].string;
		var prop = data[i].prop;
		if (string)
		{
			if (string.indexOf(data[i].subString) != -1)
				return data[i].identity;
		}
		else if (prop)
		{
			return data[i].identity;
		}
	}
	return "UNKNOWN";
}


function is_not_mym() {
    if (document.domain.indexOf("webmessenger.yahoo.com")>-1) {
        return true;
	} else if(document.location.toString().indexOf("pico.php") != -1) {
		return true;
	} else if(document.location.toString().indexOf("aero.php") != -1) {
		return true;
	} else if(document.location.toString().indexOf("yoda.php") != -1) {
		return true;
	} else {
		return false;
	}
}


// called externally
function updateFlash(account, username, cookies, l, wssid, abwssid, api_wssid, intl, lang, lgs, showArchivingConsentRoadblock, xml, allowed, firstTimer, firstName, lastName) {
  loginCookies = cookies;
  lf = l;
  if (is_not_mym() || allowed == "true") {
  	var movie = getFlashMovieObject(myName);
	movie.userSignedIn(account, username, cookies, wssid, abwssid, api_wssid, intl, lang, lgs, showArchivingConsentRoadblock, xml, allowed, firstTimer, firstName, lastName);
  	focusMe();
  } else {
    var base = document.location.toString();
    var bArray = base.split("/");
    bArray.pop();
    base = bArray.join("/");
  	document.location = base + "/inviteonly.html";
  }
}

var noWarning = true;
var scrollTimer = 0;

var alertMsg = "You will not be able to send and receive instant messages anymore";
function setAlertMsg(s){
  alertMsg = s
}

window.onbeforeunload = function(e) {
	if (!e) e = event;
	if (noWarning) return;
	e.returnValue = alertMsg;
}

var plugin;
var safari_growl_plugin_enabled = false;

function advancedNotify(yid, msg) {
	if(!safari_growl_plugin_enabled) return;
	
	msg = unescape(msg);

	if(!plugin) {
            plugin = document.embeds["SafariWebIM"];
    }
    plugin.sendGrowlNotification(yid, msg);
}

function startNotify(msg) {

	msg = unescape(msg);
	var windowSize = 100;
	var offset = -1;
	var msg = msg +" - ";
	stopNotify();
	// setInterval causes delayed event to be queued-up
	// which makes the marquee very jumpy at times.
	var f = function() {
		offset = (offset+1)%msg.length;
		var txt = msg.substr(offset, windowSize);
		while (txt.length<windowSize) {
			txt += msg.substr(0, windowSize-txt.length);
		}
		document.title = txt;
		scrollTimer = setTimeout(f, 100);
	};
	scrollTimer = setTimeout( f, 100);
}

function stopNotify() {
	if (scrollTimer) {
		clearTimeout(scrollTimer)
		scrollTimer=0;
		document.title=myTitle;
	}
}

var myTitle = document.title;
function intlTitle(t){
  myTitle = t;
  document.title = t;
}

/* --disabled. improper i18n and mac support.--
var savedFontSize=0;
function fontWatch() {
  var canari = document.getElementById("canari");
  if (!canari) return;
  var height = canari.offsetHeight;
  if (height != savedFontSize) {
    try {
      var movie = getFlashMovieObject(myName);
      movie.defaultFontSizeChanged(height*10/19); // normalize somewhat
      savedFontSize = height;
    } catch (e) {
      // oh nooz. too soon.
    }
  }
}
document.writeln("<span id=canari>This_is_some_text</span>");
setInterval(fontWatch, 100);
*/

// used by the signed out dialog.
function reload() {
  noWarning = true;
  location.reload(true);
}
function exit(url) {
  noWarning = true;
  if (!url) url = window.exitURL || "http://webmessenger.yahoo.com/";
  location.href= url;
}

function focusMe() {
  try {
  	getFlashMovieObject(myName).focus();
  } catch(e) {}
}

function appReady() {
  noWarning = false;
}

// called via ExternalInterface
function IsFocused() {	return IsFocusedHandler.Impl(); }
function IsFocusedHandler()
{
	window.onfocus = function()
	{
		window.bFocused = true;
		try {
			// focus on flash			
			getFlashMovieObject(myName).focus(); 
		} 
		catch (e) {}
	};

	// see externalnotifier for details
	if (document.hasFocus)  // IE?
	{
		IsFocusedHandler.Impl = document.hasFocus;
	}
	else // not IE
	{
		window.onblur = function()	{	window.bFocused = false; };
		IsFocusedHandler.Impl = function() { return window.bFocused; };
	}
}
IsFocusedHandler();
