/****************************************************

 iShares Global

 Author: tony.vieques@blackrock.com

 (c) Copyright 2010 BlackRock, Inc.

****************************************************/


var iSharesError,iShares,$s,$m;
//var log,warn,info,err,cprofile,cprofileEnd,cgroup,cgroupEnd,ctimer,ctimerEnd;
var STATUS_READY=2; var STATUS_OK=1; var STATUS_WARN=0; var STATUS_WAIT=-1; var STATUS_FAIL=-2;
var _STAT=2; var _ON = 1; var _OFF = 0;

//clear errors in production when they're not being handled
window.onError = function(){ return true; }

/******************************************************

DEBUG CONSOLE FUNCTIONS (in Firefox and Chrome)

******************************************************/

var hasConsole = (typeof console!="undefined" && typeof enConsole!="undefined" && enConsole );

function log(){
  if(hasConsole){ console.log(arguments); }
  else{ return false; }
};

function info(){
  if(hasConsole){ console.info(arguments); }
  else{ return false; }
};

function err(){
  if(hasConsole){ console.error(arguments); }
  else{ return false; }
};

function warn(){
  if(hasConsole){ console.warn(arguments); }
  else{ return false; }
};

function cgroup(){
  if(hasConsole){ console.group(arguments); }
  else{ return false; }
};

function cgroupEnd(){
  if(hasConsole){ console.groupEnd(arguments); }
  else{ return false; }
};

function ctimer(){
  if(hasConsole){ console.time(arguments); }
  else{ return false; }
};

function ctimerEnd(){
  if(hasConsole){ console.timeEnd(arguments); }
  else{ return false; }
};


function cprofile(){
  if(hasConsole){ console.profile(arguments); }
  else{ return false; }
};

function cprofileEnd(){
  if(hasConsole){ console.profile(arguments); }
  else{ return false; }
};


/******************************************************

IS DEF

******************************************************/
function is_def(obj){
  return(typeof obj != "undefined" && obj != null && obj != "null");
}

/******************************************************

IS FUNC

******************************************************/
function is_func(obj){
  if(is_def(jQuery)){
    //if jq is avail use built in
    return(jQuery.isFunction(obj));
  }else{
    return(typeof obj == "function");
  }
}

/******************************************************

IS EMPTY

******************************************************/
function is_empty(obj){
  if(is_def(jQuery)&&is_func(jQuery.isEmptyObject)){
    //if jq is avail use built in
    return(jQuery.isEmptyObject(obj));
  }else{
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop)){return false;}
    }
    return true;
  }
}

/******************************************************

turn On/Off

******************************************************/
function isOn(o){
  if(is_func(o.hasClass)){
    return(o.hasClass('on'));
  }else{
    alert("missing jquery or function def for isOn()");
  }
}


function changeState(o,mode){
  if(!is_def(o)){ warn("object not found"); return; }

  if(is_def(jQuery)){

     if(is_func(o.hasClass)){
       if(mode){
          if(!isOn(o)){ o.addClass('on'); }
       }else{
          if(isOn(o)){ o.removeClass('on'); }
       }
     }else{
        warn("Object in changeState does not have jquery wrapper");
        log(o);
     }
  }else{
    warn("changeState depends on jQuery");
  }
}


function show(o){
  changeState(o,true);
}

function hide(o){
  changeState(o,false);
}

function toggle(o){
  changeState(o,!isOn(o));
}

function changeStateTimed(o,time){

}


/******************************************************

Status On/Off

******************************************************/
function set_stat(key,state){
  state = (state==true?_ON:_OFF);
  $.get('/setstate.htm?'+key+'='+state, function(data) {
    log('State '+key+' is updated');
  });
}

function get_stat(key,callback){
  var data;
  $.get('/setstate.htm?'+key+'='+_STAT, function(data) {        
    log('State <'+key+'> = '+data);    
    callback(data);
  });
}      
      
function signout(){
  state = (state==true?_ON:_OFF);
  $.get('/profile/sign_out.htm', function(data) {
    log('Signout Successful');
    get_stat("auth",function(r){ log(r); });
  });
}      
      
   


/******************************************************

LEGACY REDIRECTOUTPUT - used in streamlogics_form.jsp

******************************************************/
function redirectOutput(myForm) {
  var sWidth = (screen.width) ? screen.width : 0;
  if (sWidth > 1000){  // if the screen res is higher than 800x600 then open the large auditorium
    aWidth = 1014;
    aHeight = 678;
  }
  else{
    aWidth = 790;
    aHeight = 510;
  }
  var w = window.open("about:blank","Popup_Window","status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=yes,height=" + aHeight + ",width=" + aWidth);
  myForm.target = 'Popup_Window';
  return true;
}

function disableForesee(){
  if(window.foresee){
    foresee.triggerParms["displayMode"] = 0;
	if( (document.getElementById("FSRInviteWin") !=null) || (document.all.FSRInviteWin != null) ){
      foresee.FSRInviteAct('0');
    }

    // This method internally checks whether the window is open
    foresee.closeTrackerWin();
  }
}

/******************************************************

LEGACY NAMEDPOPUP

******************************************************/
// generic popup function to use when a link needs to open a popup. Now toolbar is an option to show or not.
// @ page  - url for popup to display
// @ height, @ width - e.g. 800, 600  (pixel units)
// @ name   the title to display for the browser popup (appears at top of browser)
// @ suppressToolbarFlag  - if set to "n" then do not suppress the toolbar. if set to "y" then suppress the toolbar in popup
// example of correct usage: named_tool_popup(this.href,600,800,"General Module Name","y")
function named_popup(page, height, width, name, suppressToolbarFlag) {
  if(name=="Fund Comparison"){
    if(!isBlocked){
      FSR.pop(100, 'later');
    }
  }
  name="";   // name reset to null currently. So even if name is passsed in, it's thrown away. Historically was this way.
  var showToolbar='no'; // don't show toolbar by default for backward compat.
  if (suppressToolbarFlag == 'n') showToolbar='yes'; // if flag is "n" this means suppression not wanted so set showToolbar to "yes".
  startWindow=this.open(page,name,"toolbar="+showToolbar+",scrollbars=yes,resizable=yes,height="+height+",width="+width);
  startWindow.focus();
}

//supports the old legacy function name for tools popups
//note:function aliasing only works for functions with the same "this" context
var named_tool_popup = named_popup;


/*************************************************

   (c) Copyright 2010 BlackRock, Inc.

**************************************************/

