var MS;
if(MS == undefined) {
  MS = {};
  
  MS.gId = function(id) {
    return document.getElementById(id);
  };

  MS.gName = function (name) {
	return document.getElementsByName(name);
  }


  MS.hasClassName = function(element, className) {
    var elementClassName = element.className;

    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  };

  MS.addClassName = function(element, className) {
    if (!MS.hasClassName(element, className))
      element.className += (element.className ? ' ' : '') + className;
    return element;
  };

  MS.removeClassName = function(element, className) {
    var newClass = MS.strip(element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' '));
    element.className = newClass;
    return element;
  };

  MS.strip = function(string) {
    return string.replace(/^\s+/, '').replace(/\s+$/, '');
  };
}

MS.feedback = function(url) {
  this.empty_url = "";
  this.feedback_url = url;  
  
  this.overlay_html = '<div id="ms_overlay" style="display:none">' +
                        '<div id="ms_container">' +
                          '<a href="#" onclick="MS.hide();return false" id="ms_close"></a>' +
                          '<iframe src="' + this.empty_url + '" id="ms_iframe" allowTransparency="true" scrolling="no" frameborder="0" class="loading"></iframe>' +
                        '</div>' +
                        '<div id="ms_screen"></div>' +
                      '</div>';
                      
  document.write(this.overlay_html);
  this.gId('ms_iframe').setAttribute("src", this.empty_url);
};

MS.set_position = function() {
  this.scroll_top = document.documentElement.scrollTop || document.body.scrollTop;
  this.scroll_height = document.body.scrollHeight || document.documentElement.scrollHeight;
  this.client_height = window.innerHeight || document.documentElement.clientHeight;
  this.gId('ms_screen').style.height = this.scroll_height+"px";
  this.gId('ms_container').style.top = this.scroll_top+(this.client_height*0.1)+"px";
  if (this.scroll_top+(this.client_height*0.1) == 0)
  {
	this.gId('ms_container').style.position = 'absolute';
	this.gId('ms_container').style.margin = '0px';
	this.gId('ms_container').style.top = '20px';
	var screenW = 800;
	if (parseInt(navigator.appVersion)>3)
	{
		screenW = screen.width;
	}
	else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) 
	{
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
	}
	this.gId('ms_container').style.left = (screenW / 2 - 260) + 'px';
  }

};

MS.show = function() {
  this.gId('ms_iframe').setAttribute("src", this.feedback_url);
  if (this.gId('ms_iframe').addEventListener) {
    this.gId('ms_iframe').addEventListener("load", MS.loaded, false);
  } else if (this.gId('ms_iframe').attachEvent) {
    this.gId('ms_iframe').attachEvent("onload", MS.loaded);
  }
  this.set_position();
  
  MS.addClassName(document.getElementsByTagName('html')[0], 'feedback_tab_on');
  this.gId('ms_overlay').style.display = "block";
};
  
MS.hide = function() {
  if (MS.gId('ms_iframe').addEventListener) {
    MS.gId('ms_iframe').removeEventListener("load", MS.loaded, false);
  } else if (MS.gId('ms_iframe').attachEvent) {
    MS.gId('ms_iframe').detachEvent("onload", MS.loaded);
  }
  this.gId('ms_overlay').style.display = "none";
  this.gId('ms_iframe').setAttribute("src", this.empty_url);
  MS.gId('ms_iframe').className = "loading";

  MS.removeClassName(document.getElementsByTagName('html')[0], 'feedback_tab_on');
};
  
MS.loaded = function() {
  MS.gId('ms_iframe').className = "loaded";
};

function load()
{
	if (MS.gId('ms_subscribe'))
	{
		MS.gId('ms_subscribe').onclick = function()
		{ 
			MS.show(); 
			return false; 
		}
	}
	if (MS.gId('ms_subscribe_alt'))
	{
		MS.gId('ms_subscribe_alt').onclick = function()
		{ 
			MS.show(); 
			return false; 
		}
	}

	var names = MS.gName('ms_subscribe');
	if (names.length)
	{	
		for (var i = 0; i < names.length; i++)
		{
			names[i].onclick = function()
			{
				MS.show(); 
				return false; 
			}
		}
	}

	var css = document.createElement('link');
	css.setAttribute('rel', 'stylesheet');
	css.setAttribute('href', 'http://www.mailersoft.com/css/mailersoft.css');
	css.setAttribute('type', 'text/css');

	document.getElementsByTagName('head').item(0).appendChild(css);

}

addLoadEvent(load);

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

