

// verify to see if we have defined the global namespace.
if (typeof TM === 'undefined') {
  TM = {};
}


TM.TagsMenu = function(){
	var TAG_URL = '/web2/tags.jhtml?tag=';
	//path of the 3 icons
	var trans_gif_path = "/ibo/images/passcall/passcall_trans.gif"; 
	var pel_gif_path   = "/ibo/images/passcall/passcall_pel.gif";
	var pel_arr_path   = "/ibo/images/passcall/passcall_cellphone.gif";
	return {
		
		buildTags : function(){
		  if (jQuery.browser.msie){
			jQuery("#tagsMenu li.subItem").hover( 
				function() {  //On hover over,
					jQuery(this).addClass("over");
					}, 
				function(){  //On Hover Out  
					jQuery(this).removeClass("over");
					}
				);
			}
		},
		
		// print the alerts menu
		alertsMenuItem : function(){
			var tagName = arguments[0];
			var objectName = arguments[1];
			jQuery("#"+objectName).html(this.getPAlertsMenu(tagName, objectName));		
			this.buildTags();
		},

		//returns alert menu for one given tag
		getPAlertsMenu : function (){
			var tagName = arguments[0];
			var objectName = arguments[1];
			var showRemoveMenu = arguments[2];				
			
			var tagUrl = TAG_URL + tagName;  
			var alertMenu = "<li><a href='"+tagUrl+"' class='PIntLink'><img class='Picon' src='"+trans_gif_path+"'>הצג כתבות</a></li>";
			if (showRemoveMenu){
				alertMenu += "<li><a href='#' onClick='removeLastVisitedTag(\""+tagName+"\")' class='PIntLink'>&nbsp;&nbsp;&nbsp;הסר מהרשימה</a></li>";
			}
			alertMenu += "<li><a href='#' onClick='TM.TagsMenu.openPopupWindow(\""+tagName+"\", \""+objectName+"\")'><img class='Picon' src='"+pel_gif_path+"'>התראה סלולרית</a></li>";
			return alertMenu;
		},
		
		openPopupWindow  : function(){
			var tagName = arguments[0]; //expect url encoded value
			var thisAnchor = arguments[1];			
			if (TM.Sso.isLoggedIn()){					
				var tagsList = jQuery("#tagsList").html();
				var url = "/web2/tags/passcallAllerts.jhtml?tagName="+encodeURIComponent(this.unReplaceSpecialChars(tagName)); 
				if (tagsList != null){
					url += "&otherTags=" + encodeURIComponent(tagsList);
				}
				var popupConf = "toolbar="+popupToolbar+" ,scrollbars="+popupScrollbars+" ,location="+popupLocation+" ,statusbar="+popupStatusbar+" ,menubar="+popupMenubar+" ,resizable="+popupResizable+" ,width="+popupWidth+" ,height="+popupHeight+" ,top="+popupLeft+" ,left="+popupLeft;   
				var win = window.open(url, '', popupConf );
				
			}else{
				this.showLoginBuble(thisAnchor);
			}	
		},
		
		showLoginBuble : function(){
			var thisAnchor = arguments[0];				
			var offset = jQuery("#"+thisAnchor).parent().offset();
			var thisMenu = jQuery("#pcallMain");
			thisMenu.show();
			thisMenu.css("position","absolute");
			thisMenu.css('top', offset.top + 'px');
			thisMenu.css('left', offset.left+250+ 'px');					
		},
		
		// sets the alerts link for all the tags
		alertsLink : function(){
			var tags = arguments[0];
			var objectName = arguments[1];
			jQuery("#"+objectName).html(this.getPalertsLink(tags, objectName));			
		},

		getPalertsLink : function(){
			var tags = arguments[0];
			var parentObjectName = arguments[1];
			return "<span class='PalertsLink' onClick='TM.TagsMenu.openPopupWindow(\""+tags+"\",\""+parentObjectName+"\")'><a href='#'><img src='"+pel_arr_path+"' border=0><span class='new'>חדש !</span>&nbsp;הרשם להתראה סלולרית</a></span>";
		},
		
		unReplaceSpecialChars : function ()	{
			var str = arguments[0];
			if (str != null){
				str = str.replace('~','"');	
				str = str.replace('*','\'');	
				str = str.replace('+',' ');				
				str = str.replace('^','&');
			}				
			return str;	
		},
		replaceSpace : function (str){
			while(str.indexOf(" ")!=-1){
				str =str.replace(" ","&nbsp;");
			}
			return str;
		}
		
		
	};//return
}();




var popupWidth      = 500;  
var popupHeight     = 400;
var popupLeft       = 200;
var popupTop        = 200;
var popupScrollbars = 0;  // scrollbars appears in popup ? 1=yes 0=no
var popupLocation   = 0;  // location   appears in popup ? 1=yes 0=no
var popupStatusbar  = 0;  // statusbar  appears in popup ? 1=yes 0=no
var popupMenubar    = 0;  // menubar    appears in popup ? 1=yes 0=no
var popupResizable  = 0;  // is popup resizable ?          1=yes 0=no
var popupToolbar    = 0;  // toolbar    appears in popup ? 1=yes 0=no